Merge branch 'master' into multi_author_display
commit
f101f0dc20
|
@ -491,24 +491,48 @@ class Campaign(models.Model):
|
|||
else:
|
||||
self.problems.append(_('A campaign must initialized properly before it can be launched'))
|
||||
may_launch = False
|
||||
if self.target < Decimal(settings.UNGLUEIT_MINIMUM_TARGET):
|
||||
self.problems.append(_('A campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
|
||||
if not self.description:
|
||||
self.problems.append(_('A campaign must have a description'))
|
||||
may_launch = False
|
||||
if self.type==REWARDS and self.deadline.date()- date_today() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
|
||||
self.problems.append(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
|
||||
may_launch = False
|
||||
elif self.deadline.date()- date_today() < timedelta(days=0):
|
||||
self.problems.append(_('The chosen closing date is in the past'))
|
||||
may_launch = False
|
||||
if self.type==BUY2UNGLUE and self.work.offers.filter(price__gt=0,active=True).count()==0:
|
||||
self.problems.append(_('You can\'t launch a buy-to-unglue campaign before setting a price for your ebooks' ))
|
||||
may_launch = False
|
||||
if self.type==BUY2UNGLUE and EbookFile.objects.filter(edition__work=self.work).count()==0:
|
||||
self.problems.append(_('You can\'t launch a buy-to-unglue campaign if you don\'t have any ebook files uploaded' ))
|
||||
may_launch = False
|
||||
if self.type==BUY2UNGLUE and ((self.cc_date_initial is None) or (self.cc_date_initial > datetime.combine(settings.MAX_CC_DATE, datetime.min.time())) or (self.cc_date_initial < now())):
|
||||
self.problems.append(_('You must set an initial Ungluing Date that is in the future and not after %s' % settings.MAX_CC_DATE ))
|
||||
may_launch = False
|
||||
if self.type==REWARDS:
|
||||
if self.deadline:
|
||||
if self.deadline.date()- date_today() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
|
||||
self.problems.append(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
|
||||
may_launch = False
|
||||
else:
|
||||
self.problems.append(_('A pledge campaign must have a closing date'))
|
||||
may_launch = False
|
||||
if self.target:
|
||||
if self.target < Decimal(settings.UNGLUEIT_MINIMUM_TARGET):
|
||||
self.problems.append(_('A pledge campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
|
||||
may_launch = False
|
||||
else:
|
||||
self.problems.append(_('A campaign must have a target'))
|
||||
may_launch = False
|
||||
if self.type==BUY2UNGLUE:
|
||||
if self.work.offers.filter(price__gt=0,active=True).count()==0:
|
||||
self.problems.append(_('You can\'t launch a buy-to-unglue campaign before setting a price for your ebooks' ))
|
||||
may_launch = False
|
||||
if EbookFile.objects.filter(edition__work=self.work).count()==0:
|
||||
self.problems.append(_('You can\'t launch a buy-to-unglue campaign if you don\'t have any ebook files uploaded' ))
|
||||
may_launch = False
|
||||
if ((self.cc_date_initial is None) or (self.cc_date_initial > datetime.combine(settings.MAX_CC_DATE, datetime.min.time())) or (self.cc_date_initial < now())):
|
||||
self.problems.append(_('You must set an initial Ungluing Date that is in the future and not after %s' % settings.MAX_CC_DATE ))
|
||||
may_launch = False
|
||||
if self.target:
|
||||
if self.target < Decimal(settings.UNGLUEIT_MINIMUM_TARGET):
|
||||
self.problems.append(_('A buy-to-unglue campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
|
||||
may_launch = False
|
||||
else:
|
||||
self.problems.append(_('A buy-to-unglue campaign must have a target'))
|
||||
may_launch = False
|
||||
if self.type==THANKS:
|
||||
if self.work.offers.filter(price__gt=0,active=True).count()==0:
|
||||
self.problems.append(_('You can\'t launch a thanks-for-ungluing campaign without suggesting a contribution amount > 0' ))
|
||||
may_launch = False
|
||||
if EbookFile.objects.filter(edition__work=self.work).count()==0:
|
||||
self.problems.append(_('You can\'t launch a thanks-for-ungluing campaign if you don\'t have any ebook files uploaded' ))
|
||||
may_launch = False
|
||||
except Exception as e :
|
||||
self.problems.append('Exception checking launchability ' + str(e))
|
||||
may_launch = False
|
||||
|
@ -853,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 = ""
|
||||
|
||||
|
@ -865,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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -575,6 +575,8 @@ class CampaignTests(TestCase):
|
|||
t.save()
|
||||
self.assertEqual(w2.percent_of_goal(), 23)
|
||||
|
||||
self.assertEqual(c1.launchable, False)
|
||||
c1.description="description"
|
||||
self.assertEqual(c1.launchable, True)
|
||||
c1.work.create_offers()
|
||||
self.assertEqual(c1.work.offers.count(), 2)
|
||||
|
|
|
@ -419,7 +419,7 @@ Please fix the following before launching your campaign:
|
|||
{% ifequal campaign_status 'INITIALIZED' %}
|
||||
<div class="tabs-3">
|
||||
{% if not is_preview or request.user.is_staff %}
|
||||
{% if campaign.description and campaign.target and campaign.deadline and campaign.launchable %}
|
||||
{% if campaign.launchable %}
|
||||
<p>Before you hit launch:</p>
|
||||
<ul class="bullets">
|
||||
<li>Have you proofread your campaign? (Make sure to spellcheck!)</li>
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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, [])
|
||||
|
||||
|
|
Loading…
Reference in New Issue