Skip to content

Commit

Permalink
Disallow start date change if campaign has started
Browse files Browse the repository at this point in the history
  • Loading branch information
zeantsoi committed Jun 24, 2015
1 parent ec607e7 commit 48691ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion r2/r2/controllers/promotecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions r2/r2/lib/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")),
Expand Down
4 changes: 4 additions & 0 deletions r2/r2/models/promo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions r2/r2/templates/promotelinkbase.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
value="${value}" id="${name}" class="rounded styled-input" readonly="readonly" size="10" />
<div id="datepicker-${name}" class="datepicker"></div>
${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")}
<script type="text/javascript">
Expand Down

0 comments on commit 48691ad

Please sign in to comment.