mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
Make min promotion bid dynamic
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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."
|
||||
%>
|
||||
<table class="preftable">
|
||||
@@ -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}"
|
||||
/>
|
||||
<span class="bid-info gray"></span>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user