Skip to content

Commit

Permalink
Make min promotion bid dynamic
Browse files Browse the repository at this point in the history
Updates javascript to use min bid defined in the app config instead of using a
hard-coded value, and allows admin to override min bid.

Updates validation code to allow admin to override min bid on the back end.
  • Loading branch information
shlurbee committed Aug 13, 2012
1 parent b1ed5e0 commit eeb2aa8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
18 changes: 14 additions & 4 deletions r2/r2/controllers/promotecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def POST_rm_roadblock(self, form, jquery, dates, sr):
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))
Expand Down Expand Up @@ -319,10 +320,19 @@ def POST_edit_campaign(self, form, jquery, l, indx,
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

Expand Down
3 changes: 3 additions & 0 deletions r2/r2/controllers/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,9 @@ def cast(self, val):
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),
Expand Down
2 changes: 2 additions & 0 deletions r2/r2/lib/pages/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,8 @@ def __init__(self, sr = None, link = None, listing = '',
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,
Expand Down
4 changes: 3 additions & 1 deletion r2/r2/public/static/js/sponsored.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions r2/r2/templates/promotelinkform.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h1>${title}</h1>
<%
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."
%>
<table class="preftable">
Expand Down Expand Up @@ -140,8 +140,9 @@ <h1>${title}</h1>
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}"
/>
<span class="bid-info gray"></span>
</td>
Expand Down

0 comments on commit eeb2aa8

Please sign in to comment.