mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Let sponsors safely terminate a live campaign.
This will set the campaign's end_date to now so all traffic and billing information is retained.
This commit is contained in:
@@ -338,7 +338,7 @@ def make_map():
|
||||
"traffic_viewer|rm_traffic_viewer|"
|
||||
"edit_campaign|delete_campaign|meta_promo|"
|
||||
"add_roadblock|rm_roadblock|check_inventory|"
|
||||
"refund_campaign")))
|
||||
"refund_campaign|terminate_campaign")))
|
||||
mc('/api/:action', controller='apiminimal',
|
||||
requirements=dict(action="new_captcha"))
|
||||
mc('/api/:type', controller='api',
|
||||
|
||||
@@ -669,6 +669,15 @@ class PromoteController(ListingController):
|
||||
if l and campaign:
|
||||
promote.delete_campaign(l, campaign)
|
||||
|
||||
@validatedForm(VSponsorAdmin(),
|
||||
VModhash(),
|
||||
link=VLink('link_id36'),
|
||||
campaign=VPromoCampaign("campaign_id36"))
|
||||
def POST_terminate_campaign(self, form, jquery, link, campaign):
|
||||
if link and campaign:
|
||||
promote.terminate_campaign(link, campaign)
|
||||
rc = RenderableCampaign.from_campaigns(link, campaign)
|
||||
jquery.update_campaign(campaign._fullname, rc.render_html())
|
||||
|
||||
@validatedForm(VSponsor('container'),
|
||||
VModhash(),
|
||||
|
||||
@@ -305,6 +305,24 @@ def edit_campaign(link, campaign, dates, bid, cpm, sr, priority):
|
||||
hooks.get_hook('promote.edit_campaign').call(link=link, campaign=campaign)
|
||||
|
||||
|
||||
def terminate_campaign(link, campaign):
|
||||
if not is_live_promo(link, campaign):
|
||||
return
|
||||
|
||||
now = promo_datetime_now()
|
||||
original_end = campaign.end_date
|
||||
dates = [campaign.start_date, now]
|
||||
sr = Subreddit._by_name(campaign.sr_name) if campaign.sr_name else None
|
||||
|
||||
# NOTE: this will delete PromotionWeights after and including now.date()
|
||||
edit_campaign(link, campaign, dates, campaign.bid, campaign.cpm, sr,
|
||||
campaign.priority)
|
||||
|
||||
msg = 'terminated campaign %s (original end %s)' % (campaign._id,
|
||||
original_end.date())
|
||||
PromotionLog.add(link, msg)
|
||||
|
||||
|
||||
def delete_campaign(link, campaign):
|
||||
PromotionWeights.delete_unfinished(link, campaign._id)
|
||||
void_campaign(link, campaign)
|
||||
|
||||
@@ -555,3 +555,11 @@ function free_campaign($campaign_row) {
|
||||
$campaign_row.find(".free").fadeOut();
|
||||
return false;
|
||||
}
|
||||
|
||||
function terminate_campaign($campaign_row) {
|
||||
var link_id36 = $("#campaign").find('*[name="link_id36"]').val(),
|
||||
campaign_id36 = $campaign_row.data('campaign_id36')
|
||||
$.request("terminate_campaign", {"campaign_id36": campaign_id36,
|
||||
"link_id36": link_id36},
|
||||
null, true, "json", false);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,12 @@
|
||||
${_("view live")}
|
||||
</button>
|
||||
%endif
|
||||
|
||||
%if thing.is_live and c.user_is_sponsor:
|
||||
<button class="terminate fancybutton" onclick="terminate_campaign(${jquery_row})">
|
||||
${_("terminate")}
|
||||
</button>
|
||||
%endif
|
||||
%endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user