Permalink
Browse files

Don't display captcha and ratelimit fields when they aren't needed.

  • Loading branch information...
1 parent 766dd00 commit 2248c4a2f3dc7e2db1f1268f6368a71f4766a760 @bboe bboe committed with spladug Apr 17, 2012
Showing with 9 additions and 12 deletions.
  1. +9 −12 r2/r2/controllers/validator/validator.py
@@ -237,21 +237,18 @@ def validatedForm(self, self_method, responder, simple_vals, param_vals,
# clear out the status line as a courtesy
form.set_html(".status", "")
- # handle specific errors
- if c.errors.errors:
- handled_captcha = handled_ratelimit = False
- for v in simple_vals:
- if not handled_captcha and isinstance(v, VCaptcha):
- form.has_errors('captcha', errors.BAD_CAPTCHA)
- form.new_captcha()
- handled_captcha = True
- elif not handled_ratelimit and isinstance(v, VRatelimit):
- form.ratelimit(v.seconds)
- handled_ratelimit = True
-
# do the actual work
val = self_method(self, form, responder, *a, **kw)
+ # add data to the output on some errors
+ for validator in simple_vals:
+ if (isinstance(validator, VCaptcha) and
+ form.has_errors('captcha', errors.BAD_CAPTCHA)):
+ form.new_captcha()
+ elif (isinstance(validator, VRatelimit) and
+ form.has_errors('ratelimit', errors.RATELIMIT)):
+ form.ratelimit(validator.seconds)
+
if val:
return val
else:

0 comments on commit 2248c4a

Please sign in to comment.