(Python 2.7)Since decorators can not share variables with the function they are decorating, how can I make/pass object_list to the decorating function? I have a few of functions that will be using raw_turn_over_mailer() decorator and I would like to keep object_list to the local decorated function if possible.
def raw_turn_over_mailer(function):
@wraps(function)
def wrapper(requests):
original_function = function(requests)
if object_list:
....
return original_function
return wrapper
@raw_turn_over_mailer
def one(requests):
object_list = [x for x in requests
if x.account_type.name == 'AccountType1']
@raw_turn_over_mailer
def two(requests):
object_list = [x for x in requests
if x.account_type.name == 'AccountType2']
@periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*"))
def turn_over_mailer():
HOURS = 1000
requests = Request.objects.filter(completed=False, date_due__gte=hours_ahead(0), date_due__lte=hours_ahead(HOURS))
if requests:
one(requests)
two(requests)