diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index a8c36268b..2ad4d213c 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -283,7 +283,8 @@ class PromoteController(ListingController): business_days = False, admin_override = True), l = VLink('link_id'), - bid = VBid('bid', 'link_id', 'sr'), + bid = VFloat('bid', min=0, max=g.max_promote_bid, + coerce=False, error=errors.BAD_BID), sr = VSubmitSR('sr', promotion=True), indx = VInt("indx"), targeting = VLength("targeting", 10)) @@ -319,10 +320,19 @@ class PromoteController(ListingController): if form.has_errors('bid', errors.BAD_BID): return - if bid is None or float(bid) / duration < g.min_promote_bid: + # minimum bid depends on user privilege and targeting, checked here + # instead of in the validator b/c current duration is needed + if c.user_is_admin: + min_daily_bid = 0 + elif targeting == 'one': + min_daily_bid = g.min_promote_bid * 1.5 + else: + min_daily_bid = g.min_promote_bid + + if bid is None or bid / duration < min_daily_bid: c.errors.add(errors.BAD_BID, field = 'bid', - msg_params = {"min": g.min_promote_bid, - "max": g.max_promote_bid}) + msg_params = {'min': min_daily_bid, + 'max': g.max_promote_bid}) form.has_errors('bid', errors.BAD_BID) return diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 9c9b02082..e7a043819 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -1160,6 +1160,9 @@ class VFloat(VNumber): return float(val) class VBid(VNumber): + ''' + DEPRECATED. Use VFloat instead and check bid amount in function body. + ''' def __init__(self, bid, link_id, sr): self.duration = 1 VNumber.__init__(self, (bid, link_id, sr), diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 620afcb2e..824c9ed63 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -3041,6 +3041,8 @@ class PromoteLinkForm(Templated): self.market, self.promo_counter = \ Promote_Graph.get_market(None, start_date, end_date) + self.min_daily_bid = 0 if c.user_is_admin else g.min_promote_bid + Templated.__init__(self, sr = sr, datefmt = datefmt, timedeltatext = timedeltatext, diff --git a/r2/r2/public/static/js/sponsored.js b/r2/r2/public/static/js/sponsored.js index 81b61afac..226956c68 100644 --- a/r2/r2/public/static/js/sponsored.js +++ b/r2/r2/public/static/js/sponsored.js @@ -10,7 +10,9 @@ function update_bid(elem) { Date.parse(form.find('*[name="startdate"]').val())) / (86400*1000)); ndays = Math.round(ndays); - var minimum_daily_bid = (is_targeted ? 30 : 20); + // min bid is slightly higher for targeted promos + var minimum_daily_bid = is_targeted ? $("#bid").data("min_daily_bid") * 1.5 : + $("#bid").data("min_daily_bid"); $(".minimum-spend").removeClass("error"); if (bid < ndays * minimum_daily_bid) { $(".bid-info").addClass("error"); diff --git a/r2/r2/templates/promotelinkform.html b/r2/r2/templates/promotelinkform.html index e4bb7071b..cdd3b983b 100644 --- a/r2/r2/templates/promotelinkform.html +++ b/r2/r2/templates/promotelinkform.html @@ -92,7 +92,7 @@ ${unsafe(js.use('sponsored'))} <% start_title = "Date when your sponsored link will start running. We start new campaigns at midnight UTC+5" end_title = "Date when your sponsored link will end (at midnight UTC+5)" - targeting_title = "name of the community that you are targeting. A blank entry here means that the ad is untargeted and will run site-wise " + targeting_title = "name of the community that you are targeting. A blank entry here means that the ad is untargeted and will run site-wide " newcamp_title = "click to create a new campaign. To edit an existing campaing in the table below, click the 'edit' button." %> @@ -140,8 +140,9 @@ ${unsafe(js.use('sponsored'))} style="width:auto" onchange="update_bid(this)" onkeyup="update_bid(this)" - title="Minimum is $${'%.2f' % g.min_promote_bid} per day, or $${'%.2f' % (g.min_promote_bid * 1.5)} per day targeted" - value="${'%.2f' % (g.min_promote_bid * 5)}" + title="Minimum is $${'%.2f' % thing.min_daily_bid} per day, or $${'%.2f' % (thing.min_daily_bid * 1.5)} per day targeted" + value="${'%.2f' % (thing.min_daily_bid * 5)}" + data-min_daily_bid="${thing.min_daily_bid}" />