From 48691ad57dd6ddc411c47eb278c266e402d982db Mon Sep 17 00:00:00 2001 From: zeantsoi Date: Fri, 19 Jun 2015 19:39:58 -0700 Subject: [PATCH] Disallow start date change if campaign has started --- r2/r2/controllers/promotecontroller.py | 12 +++++++++++- r2/r2/lib/errors.py | 1 + r2/r2/models/promo.py | 4 ++++ r2/r2/templates/promotelinkbase.html | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index c5e2895580..77d3733311 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -1039,7 +1039,17 @@ def POST_edit_campaign(self, form, jquery, link, campaign_id36, min_start, max_start, max_end = promote.get_date_limits( link, c.user_is_sponsor) - if start.date() < min_start: + + if campaign_id36: + promo_campaign = PromoCampaign._byID36(campaign_id36) + if (promote.is_promoted(link) and + promo_campaign.start_date.date() <= min_start and + start != promo_campaign.start_date and + promo_campaign.is_paid): + c.errors.add(errors.START_DATE_CANNOT_CHANGE, field='startdate') + form.has_errors('startdate', errors.START_DATE_CANNOT_CHANGE) + return + elif start.date() < min_start: c.errors.add(errors.DATE_TOO_EARLY, msg_params={'day': min_start.strftime("%m/%d/%Y")}, field='startdate') diff --git a/r2/r2/lib/errors.py b/r2/r2/lib/errors.py index ce29094b52..5faece9bc7 100644 --- a/r2/r2/lib/errors.py +++ b/r2/r2/lib/errors.py @@ -100,6 +100,7 @@ ('BAD_DATE_RANGE', _('the dates need to be in order and not identical')), ('DATE_TOO_LATE', _('please enter a date %(day)s or earlier')), ('DATE_TOO_EARLY', _('please enter a date %(day)s or later')), + ('START_DATE_CANNOT_CHANGE', _('start date cannot be changed')), ('BAD_ADDRESS', _('address problem: %(message)s')), ('BAD_CARD', _('card problem: %(message)s')), ('TOO_LONG', _("this is too long (max: %(max_length)s)")), diff --git a/r2/r2/models/promo.py b/r2/r2/models/promo.py index e3d715a19b..62d1df6dd1 100644 --- a/r2/r2/models/promo.py +++ b/r2/r2/models/promo.py @@ -493,6 +493,10 @@ def location_str(self): else: return g.locations[self.location.country]['name'] + @property + def is_paid(self): + return self.trans_id != 0 or self.priority == 'house' + def is_freebie(self): return self.trans_id < 0 diff --git a/r2/r2/templates/promotelinkbase.html b/r2/r2/templates/promotelinkbase.html index 9b94c12668..76ec07be07 100644 --- a/r2/r2/templates/promotelinkbase.html +++ b/r2/r2/templates/promotelinkbase.html @@ -57,6 +57,7 @@ value="${value}" id="${name}" class="rounded styled-input" readonly="readonly" size="10" />
${error_field("BAD_DATE", name, "div")} + ${error_field("START_DATE_CANNOT_CHANGE", name, "div")} ${error_field("DATE_TOO_EARLY", name, "div")} ${error_field("DATE_TOO_LATE", name, "div")}