mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
VBid to validate promoted link bids.
This commit is contained in:
@@ -65,6 +65,7 @@ from r2.lib.validator import (
|
||||
validatedForm,
|
||||
ValidCard,
|
||||
ValidIP,
|
||||
VBid,
|
||||
VBoolean,
|
||||
VByName,
|
||||
VDate,
|
||||
@@ -486,8 +487,8 @@ class PromoteController(ListingController):
|
||||
business_days=False,
|
||||
sponsor_override=True),
|
||||
link=VLink('link_id'),
|
||||
bid=VFloat('bid', min=0, max=g.max_promote_bid,
|
||||
coerce=False, error=errors.BAD_BID),
|
||||
bid=VBid('bid', min=0, max=g.max_promote_bid,
|
||||
coerce=False, error=errors.BAD_BID),
|
||||
sr=VSubmitSR('sr', promotion=True),
|
||||
campaign_id36=nop("campaign_id36"),
|
||||
targeting=VLength("targeting", 10))
|
||||
|
||||
@@ -1402,6 +1402,17 @@ class VNumber(Validator):
|
||||
def cast(self, val):
|
||||
raise NotImplementedError
|
||||
|
||||
def _set_error(self):
|
||||
if self.max is None and self.min is None:
|
||||
range = ""
|
||||
elif self.max is None:
|
||||
range = _("%(min)d to any") % dict(min=self.min)
|
||||
elif self.min is None:
|
||||
range = _("any to %(max)d") % dict(max=self.max)
|
||||
else:
|
||||
range = _("%(min)d to %(max)d") % dict(min=self.min, max=self.max)
|
||||
self.set_error(self.error, msg_params=dict(range=range))
|
||||
|
||||
def run(self, val):
|
||||
if not val:
|
||||
return self.num_default
|
||||
@@ -1419,15 +1430,7 @@ class VNumber(Validator):
|
||||
raise ValueError, ""
|
||||
return val
|
||||
except ValueError:
|
||||
if self.max is None and self.min is None:
|
||||
range = ""
|
||||
elif self.max is None:
|
||||
range = _("%(min)d to any") % dict(min=self.min)
|
||||
elif self.min is None:
|
||||
range = _("any to %(max)d") % dict(max=self.max)
|
||||
else:
|
||||
range = _("%(min)d to %(max)d") % dict(min=self.min, max=self.max)
|
||||
self.set_error(self.error, msg_params=dict(range=range))
|
||||
self._set_error()
|
||||
|
||||
class VInt(VNumber):
|
||||
def cast(self, val):
|
||||
@@ -1437,6 +1440,9 @@ class VFloat(VNumber):
|
||||
def cast(self, val):
|
||||
return float(val)
|
||||
|
||||
class VBid(VFloat):
|
||||
def _set_error(self):
|
||||
self.set_error(self.error, msg_params=dict(min=self.min, max=self.max))
|
||||
|
||||
class VCssName(Validator):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user