fix missing launch button

t4u work removed the deadline in b2u campaigns, resulting in a failed
criterion for shooing the launch button. Have moved all the
launchability logic to the campaign model
pull/1/head
eric 2014-01-15 10:19:57 -05:00
parent 0ef2531725
commit 1b656ad76a
3 changed files with 44 additions and 18 deletions

View File

@ -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

View File

@ -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)

View File

@ -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>