VBid to validate promoted link bids.

This commit is contained in:
Brian Simpson
2013-09-11 16:26:23 -04:00
parent 3b35f147f2
commit d5dacda6d8
2 changed files with 18 additions and 11 deletions

View File

@@ -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))

View File

@@ -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):
"""