validator: Correct BAD_NUMBER when min or max was None.

This commit is contained in:
Andre D
2012-09-21 17:53:49 -05:00
committed by Neil Williams
parent 34ca0edd21
commit bf05f4bb79
2 changed files with 10 additions and 3 deletions

View File

@@ -55,7 +55,7 @@ error_list = dict((
('USER_DOESNT_EXIST', _("that user doesn't exist")),
('NO_USER', _('please enter a username')),
('INVALID_PREF', "that preference isn't valid"),
('BAD_NUMBER', _("that number isn't in the right range (%(min)d to %(max)d)")),
('BAD_NUMBER', _("that number isn't in the right range (%(range)s)")),
('BAD_STRING', _("you used a character here that we can't handle")),
('BAD_BID', _("your bid must be at least $%(min)d per day and no more than to $%(max)d in total.")),
('ALREADY_SUB', _("that link has already been submitted")),

View File

@@ -1184,8 +1184,15 @@ class VNumber(Validator):
raise ValueError, ""
return val
except ValueError:
self.set_error(self.error, msg_params = dict(min=self.min,
max=self.max))
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))
class VInt(VNumber):
def cast(self, val):