Commits

George Notaras committed fddf4aa

Added support for reCaptcha field validation overriding

Comments (0)

Files changed (4)

 Read the following page for more information:
   - http://code.google.com/apis/recaptcha/docs/customization.html
 
+RECAPTCHA_VALIDATION_OVERRIDE: This is a boolean setting which makes it possible
+to override the validation of the reCaptcha field. This is meant to be enabled
+only when testing your application's reCaptcha-protected forms.
+
 Example configuration:
 
 RECAPTCHA_PUBLIC_KEY  = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

src/recaptcha_works/__init__.py

 - migration to the Google-hosted reCaptcha API
 - extension of the available application settings
 - addition of a decorator that adds the remote IP to the submitted form
+- support for overriding the reCaptcha field validation to facilitate
+  form testing
 
 More information
 ----------------

src/recaptcha_works/fields.py

         
         value = super(RecaptchaField, self).clean(value)
         challenge, response, remote_ip = value
+        
+        if settings.RECAPTCHA_VALIDATION_OVERRIDE:
+            return value
         if not challenge:
             raise forms.ValidationError(self.error_messages['challenge-error'])
         if not response:

src/recaptcha_works/settings.py

 '''
 RECAPTCHA_HTML = getattr(settings, 'RECAPTCHA_HTML', _RECAPTCHA_HTML)
 
+# RECAPTCHA_VALIDATION_OVERRIDE, if set to True, makes it possible to override
+# the validation of the reCaptcha field. This is supposed to be used when
+# testing forms.
+RECAPTCHA_VALIDATION_OVERRIDE = getattr(settings, 'RECAPTCHA_VALIDATION_OVERRIDE', False)
+