Adding an optional flag to Account.update_status, which by default, send notices only if the status is *changing*.

Set send_notice_on_change_only = False to send notice based on new_status regardless of old status.  (Useful for initialization)
pull/1/head
Raymond Yee 2013-08-08 13:31:38 -04:00
parent 27bc134fa4
commit cf7160b72d
2 changed files with 12 additions and 5 deletions

View File

@ -397,9 +397,12 @@ class Account(models.Model):
return 'ACTIVE'
def update_status( self, value=None):
def update_status( self, value=None, send_notice_on_change_only=True):
"""set Account.status = value unless value is None, in which case, we set Account.status=self.calculated_status()
fire off associated notifications
By default, send notices only if the status is *changing*. Set send_notice_on_change_only = False to
send notice based on new_status regardless of old status. (Useful for initialization)
"""
old_status = self.status
@ -411,7 +414,7 @@ class Account(models.Model):
self.status = new_status
self.save()
if old_status != new_status:
if not send_notice_on_change_only or (old_status != new_status):
logger.info( "Account status change: %d %s %s", instance.pk, old_status, new_status)

View File

@ -19,8 +19,12 @@ from regluit.utils.localdatetime import date_today
#task to update the status of accounts
@task
def update_account_status(all_accounts=True):
"""update the status of all Accounts"""
def update_account_status(all_accounts=True, send_notice_on_change_only=True):
"""update the status of all Accounts
By default, send notices only if the status is *changing*. Set send_notice_on_change_only = False to
send notice based on new_status regardless of old status. (Useful for initialization)
"""
errors = []
if all_accounts:
@ -34,7 +38,7 @@ def update_account_status(all_accounts=True):
for account in accounts_to_calc:
try:
account.update_status()
account.update_status(send_notice_on_change_only=send_notice_on_change_only)
except Exception, e:
errors.append(e)