From 1b656ad76a08036946a4c86cbcbbb9309c154781 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 15 Jan 2014 10:19:57 -0500 Subject: [PATCH] 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 --- core/models.py | 58 +++++++++++++++++-------- core/tests.py | 2 + frontend/templates/manage_campaign.html | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/core/models.py b/core/models.py index 75b88085..d506bae5 100755 --- a/core/models.py +++ b/core/models.py @@ -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 diff --git a/core/tests.py b/core/tests.py index e90d5f3b..64a7f650 100755 --- a/core/tests.py +++ b/core/tests.py @@ -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) diff --git a/frontend/templates/manage_campaign.html b/frontend/templates/manage_campaign.html index f1ee3f37..03b4db16 100644 --- a/frontend/templates/manage_campaign.html +++ b/frontend/templates/manage_campaign.html @@ -419,7 +419,7 @@ Please fix the following before launching your campaign: {% ifequal campaign_status 'INITIALIZED' %}
{% if not is_preview or request.user.is_staff %} - {% if campaign.description and campaign.target and campaign.deadline and campaign.launchable %} + {% if campaign.launchable %}

Before you hit launch: