This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Limit the number of campaigns per promoted link

  • Loading branch information...
1 parent 7a1bc4e commit 37a476677f42c39667f6bd067320f4bf740098bc @kemitche kemitche committed with spladug Dec 31, 2012
View
@@ -316,6 +316,7 @@ ad_domain = http://reddit.local
allowed_pay_countries = United States, United Kingdom, Canada
sponsors =
selfserve_support_email = selfservesupport@mydomain.com
+MAX_CAMPAIGNS_PER_LINK = 100
# authorize.net credentials (blank authorizenetapi to disable)
authorizenetapi =
@@ -387,6 +387,17 @@ def POST_edit_campaign(self, form, jquery, l, campaign_id36,
errors.BAD_FUTURE_DATE, errors.BAD_DATE_RANGE)):
return
+ # Limit the number of PromoCampaigns a Link can have
+ # Note that the front end should prevent the user from getting
+ # this far
+ existing_campaigns = list(PromoCampaign._by_link(l._id))
+ if len(existing_campaigns) > g.MAX_CAMPAIGNS_PER_LINK:
+ c.errors.add(errors.TOO_MANY_CAMPAIGNS,
+ msg_params={'count': g.MAX_CAMPAIGNS_PER_LINK},
+ field='title')
+ form.has_errors('title', errors.TOO_MANY_CAMPAIGNS)
+ return
+
duration = max((end - start).days, 1)
if form.has_errors('bid', errors.BAD_BID):
View
@@ -88,6 +88,7 @@ class Globals(object):
'page_cache_time',
'commentpane_cache_time',
'num_mc_clients',
+ 'MAX_CAMPAIGNS_PER_LINK',
'MIN_DOWN_LINK',
'MIN_UP_KARMA',
'MIN_DOWN_KARMA',
View
@@ -113,6 +113,7 @@
('BAD_HASH', _("i don't believe you.")),
('ALREADY_MODERATOR', _('that user is already a moderator')),
('BID_LIVE', _('you cannot edit the bid of a live ad')),
+ ('TOO_MANY_CAMPAIGNS', _('you have too many campaigns for that promotion')),
('BAD_JSONP_CALLBACK', _('that jsonp callback contains invalid characters')),
))
errors = Storage([(e, e) for e in error_list.keys()])
@@ -4683,6 +4683,9 @@ table.lined-table {
margin-top: 0px;
}
+.create-promo .hidden { display: none; }
+button.new-campaign:disabled { color: gray; }
+
.bidding-history { padding-top: 10px; }
.bidding-history .linefield {
width: auto;
@@ -103,7 +103,7 @@ function targeting_off(elem) {
(function($) {
function get_flag_class(flags) {
- var css_class = "";
+ var css_class = "campaign-row";
if(flags.free) {
css_class += " free";
}
@@ -147,6 +147,7 @@ $.new_campaign = function(campaign_id36, start_date, end_date, duration,
$(".existing-campaigns table").show()
.insert_table_rows([{"id": "", "css_class": css_class,
"cells": row}], -1);
+ check_number_of_campaigns();
$.set_up_campaigns()
});
return $;
@@ -280,7 +281,7 @@ function del_campaign(elem) {
$.request("delete_campaign", {"campaign_id36": campaign_id36,
"link_id": link_id},
null, true, "json", false);
- $(elem).children(":first").delete_table_row();
+ $(elem).children(":first").delete_table_row(check_number_of_campaigns);
}
@@ -338,7 +339,22 @@ function edit_campaign(elem) {
}
}
+function check_number_of_campaigns(){
+ if ($(".campaign-row").length >= $(".existing-campaigns").data("max-campaigns")){
+ $(".error.TOO_MANY_CAMPAIGNS").fadeIn();
+ $("button.new-campaign").attr("disabled", "disabled");
+ return true;
+ } else {
+ $(".error.TOO_MANY_CAMPAIGNS").fadeOut();
+ $("button.new-campaign").removeAttr("disabled");
+ return false;
+ }
+}
+
function create_campaign(elem) {
+ if (check_number_of_campaigns()){
+ return;
+ }
cancel_edit(function() {;
init_startdate();
init_enddate();
@@ -220,7 +220,13 @@ <h1>${title}</h1>
</div>
<div class="clear"></div>
</div>
- <div class="existing-campaigns infotext rounded">
+ <div class="error TOO_MANY_CAMPAIGNS field-title infotext rounded
+ ${'hidden' if len(thing.campaigns) < g.MAX_CAMPAIGNS_PER_LINK else ''}"
+ data-MAX="${g.MAX_CAMPAIGNS_PER_LINK}" data-CAMP="${len(thing.campaigns)}">
+ <p>${_("You have too many campaigns for this link.")}&#32;
+ <a href="/promoted/new_promo/">${_("It's time to start fresh!")}</a></p>
+ </div>
+ <div class="existing-campaigns infotext rounded" data-max-campaigns="${g.MAX_CAMPAIGNS_PER_LINK}">
<table style="${'display:none' if not thing.campaigns else ''}">
<tr>
<th title="${start_title}">start</th>
@@ -230,6 +236,7 @@ <h1>${title}</h1>
<th title="${targeting_title}">targeting</th>
<th style="align:right">
<button class="new-campaign fancybutton"
+ ${'disabled="disabled"' if len(thing.campaigns) >= g.MAX_CAMPAIGNS_PER_LINK else ''}
title="${newcamp_title}"
onclick="return create_campaign(this)">+ add new</button>
</th>

0 comments on commit 37a4766

Please sign in to comment.