Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 40 lines (30 sloc) 1.098 kB
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
1 r"""
2
3 occupywallst.fields
4 ~~~~~~~~~~~~~~~~~~~
5
6 Form fields and stuff
7
8 """
9
ba06703 @thirtyseven let's have some frigging captchas
thirtyseven authored
10 from django import forms
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
11 from django.conf import settings
ba06703 @thirtyseven let's have some frigging captchas
thirtyseven authored
12 from django.utils.encoding import smart_unicode
13 from django.utils.translation import ugettext_lazy as _
14 from recaptcha.client import captcha
15
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
16 from occupywallst import widgets
17
ba06703 @thirtyseven let's have some frigging captchas
thirtyseven authored
18
19 class ReCaptchaField(forms.CharField):
20 default_error_messages = {
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
21 'captcha_invalid': _(u'Invalid captcha'),
ba06703 @thirtyseven let's have some frigging captchas
thirtyseven authored
22 }
23
24 def __init__(self, *args, **kwargs):
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
25 self.widget = widgets.ReCaptchaWidget
8fc3dcd merge, resolve conflicts
abie authored
26 self.required = False
ba06703 @thirtyseven let's have some frigging captchas
thirtyseven authored
27 super(ReCaptchaField, self).__init__(*args, **kwargs)
28
29 def clean(self, values):
30 super(ReCaptchaField, self).clean(values[1])
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
31 challenge = smart_unicode(values[0])
32 response = smart_unicode(values[1])
33 ip = smart_unicode(values[2])
34 key = settings.RECAPTCHA_PRIVATE_KEY
35 res = captcha.submit(challenge, response, key, ip)
36 if not res.is_valid:
9939315 follow pep8 documentation guidelines
Justine Tunney authored
37 raise forms.util.ValidationError(
38 self.error_messages['captcha_invalid'])
fa5d0a3 i wish ted had told me the captcha didn't bloody work :'(
Justine Tunney authored
39 return challenge
Something went wrong with that request. Please try again.