mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 06:48:01 -05:00
Validator: Add new num_default for a default number value when empty
This commit is contained in:
@@ -1463,8 +1463,8 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
type = VOneOf('type', ('public', 'private', 'restricted', 'archived')),
|
||||
link_type = VOneOf('link_type', ('any', 'link', 'self')),
|
||||
wikimode = VOneOf('wikimode', ('disabled', 'modonly', 'anyone')),
|
||||
wiki_edit_karma = VInt("wiki_edit_karma", coerce=False, min=0),
|
||||
wiki_edit_age = VInt("wiki_edit_age", coerce=False, min=0),
|
||||
wiki_edit_karma = VInt("wiki_edit_karma", coerce=False, num_default=0, min=0),
|
||||
wiki_edit_age = VInt("wiki_edit_age", coerce=False, num_default=0, min=0),
|
||||
ip = ValidIP(),
|
||||
sponsor_text =VLength('sponsorship-text', max_length = 500),
|
||||
sponsor_name =VLength('sponsorship-name', max_length = 64),
|
||||
|
||||
@@ -1157,11 +1157,13 @@ class VBoolean(Validator):
|
||||
|
||||
class VNumber(Validator):
|
||||
def __init__(self, param, min=None, max=None, coerce = True,
|
||||
error = errors.BAD_NUMBER, *a, **kw):
|
||||
error=errors.BAD_NUMBER, num_default=None,
|
||||
*a, **kw):
|
||||
self.min = self.cast(min) if min is not None else None
|
||||
self.max = self.cast(max) if max is not None else None
|
||||
self.coerce = coerce
|
||||
self.error = error
|
||||
self.num_default = num_default
|
||||
Validator.__init__(self, param, *a, **kw)
|
||||
|
||||
def cast(self, val):
|
||||
@@ -1169,7 +1171,7 @@ class VNumber(Validator):
|
||||
|
||||
def run(self, val):
|
||||
if not val:
|
||||
return
|
||||
return self.num_default
|
||||
try:
|
||||
val = self.cast(val)
|
||||
if self.min is not None and val < self.min:
|
||||
|
||||
Reference in New Issue
Block a user