diff options
Diffstat (limited to 'recaptcha/widgets.py')
-rw-r--r-- | recaptcha/widgets.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/recaptcha/widgets.py b/recaptcha/widgets.py new file mode 100644 index 0000000..45dfd7e --- /dev/null +++ b/recaptcha/widgets.py @@ -0,0 +1,15 @@ +from django import forms +from django.utils.safestring import mark_safe +from django.conf import settings +from recaptcha.client import captcha + +class ReCaptcha(forms.widgets.Widget): + recaptcha_challenge_name = 'recaptcha_challenge_field' + recaptcha_response_name = 'recaptcha_response_field' + + def render(self, name, value, attrs=None): + return mark_safe(u'%s' % captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY)) + + def value_from_datadict(self, data, files, name): + return [data.get(self.recaptcha_challenge_name, None), + data.get(self.recaptcha_response_name, None)] |