Skip to content
Browse files

Validator: Add new num_default for a default number value when empty

  • Loading branch information...
1 parent 6e976a3 commit 288d786092dc434841406848576144490c199c67 @andre-d committed Sep 28, 2012
Showing with 6 additions and 4 deletions.
  1. +2 −2 r2/r2/controllers/api.py
  2. +4 −2 r2/r2/controllers/validator/validator.py
View
4 r2/r2/controllers/api.py
@@ -1463,8 +1463,8 @@ def POST_upload_sr_img(self, file, header, sponsor, name, form_id, img_type):
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),
View
6 r2/r2/controllers/validator/validator.py
@@ -1157,19 +1157,21 @@ def param_docs(self):
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):
raise NotImplementedError
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:

0 comments on commit 288d786

Please sign in to comment.
Something went wrong with that request. Please try again.