Merge pull request #281 from Gluejar/fix_broken_b2u

search code for dependence on deadline being not null
pull/1/head
Raymond Yee 2014-01-15 15:09:38 -08:00
commit 3ad4427f55
5 changed files with 15 additions and 8 deletions

View File

@ -877,6 +877,8 @@ class Campaign(models.Model):
@property
def countdown(self):
from math import ceil
if not self.deadline:
return ''
time_remaining = self.deadline - now()
countdown = ""
@ -889,7 +891,11 @@ class Campaign(models.Model):
else:
countdown = "Seconds"
return countdown
return countdown
@property
def deadline_or_now(self):
return self.deadline if self.deadline else now()
@classmethod
def latest_ending(cls):

View File

@ -197,7 +197,7 @@ def handle_transaction_failed(sender,transaction=None, **kwargs):
return
# window for recharging
recharge_deadline = transaction.campaign.deadline + datetime.timedelta(settings.RECHARGE_WINDOW)
recharge_deadline = transaction.campaign.deadline_or_now + datetime.timedelta(settings.RECHARGE_WINDOW)
notification.send([transaction.user], "pledge_failed", {
'transaction':transaction,

View File

@ -1611,12 +1611,13 @@ def rh_tools(request):
if claim.campaign_form.is_valid():
new_campaign = claim.campaign_form.save(commit=False)
if new_campaign.type==BUY2UNGLUE:
new_campaign.deadline = date_today() + settings.B2U_TERM
new_campaign.target = D(settings.UNGLUEIT_MAXIMUM_TARGET)
new_campaign.set_cc_date_initial()
else:
elif new_campaign.type==REWARDS:
new_campaign.deadline = date_today() + timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE))
new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET)
elif new_campaign.type==THANKS:
new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET)
new_campaign.save()
claim.campaign_form.save_m2m()
else:

View File

@ -694,7 +694,7 @@ class PaymentManager( object ):
the redirect url will be None
'''
# set the expiry date based on the campaign deadline
expiry = campaign.deadline + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
expiry = campaign.deadline_or_now + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
t = Transaction.create(amount=0,
host = host,
@ -841,7 +841,7 @@ class PaymentManager( object ):
else:
# cancel old transaction, send user to choose new payment path
# set the expiry date based on the campaign deadline
expiry = transaction.campaign.deadline + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
expiry = transaction.campaign.deadline_or_now + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
t = Transaction.create(amount=0,
max_amount=amount,
currency=transaction.currency,
@ -857,7 +857,7 @@ class PaymentManager( object ):
elif requires_explicit_preapprovals and (amount > transaction.max_amount or expiry != transaction.date_expired):
# set the expiry date based on the campaign deadline
expiry = transaction.campaign.deadline + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
expiry = transaction.campaign.deadline_or_now + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
# Start a new transaction for the new amount
t = Transaction.create(amount=amount,

View File

@ -480,7 +480,7 @@ class Account(models.Model):
pm = PaymentManager()
for transaction in transactions_to_recharge:
# check whether we are still within the window to recharge
if (now() - transaction.campaign.deadline) < datetime.timedelta(settings.RECHARGE_WINDOW):
if (now() - transaction.campaign.deadline_or_now) < datetime.timedelta(settings.RECHARGE_WINDOW):
logger.info("Recharging transaction {0} w/ status {1}".format(transaction.id, transaction.status))
pm.execute_transaction(transaction, [])