def test_object(self): captcha = MathCaptcha('1 * 2') self.assertFalse(captcha.validate(1)) self.assertTrue(captcha.validate(2)) restored = MathCaptcha.from_hash(captcha.hashed) self.assertEqual(captcha.question, restored.question) with self.assertRaises(ValueError): MathCaptcha.from_hash(captcha.hashed[:40])
def test_object(self): captcha = MathCaptcha('1 * 2') self.assertFalse( captcha.validate(1) ) self.assertTrue( captcha.validate(2) ) restored = MathCaptcha.from_hash(captcha.hashed) self.assertEqual( captcha.question, restored.question ) with self.assertRaises(ValueError): MathCaptcha.from_hash(captcha.hashed[:40])
def __init__(self, data=None, *args, **kwargs): super(CaptchaRegistrationForm, self).__init__( data, *args, **kwargs ) # Load data self.tampering = False if data is None or 'captcha_id' not in data: self.captcha = MathCaptcha() else: try: self.captcha = MathCaptcha.from_hash(data['captcha_id']) except ValueError: self.captcha = MathCaptcha() self.tampering = True # Set correct label self.fields['captcha'].label = pgettext( 'Question for a mathematics-based CAPTCHA, ' 'the %s is an arithmetic problem', 'What is %s?' ) % self.captcha.display self.fields['captcha_id'].initial = self.captcha.hashed
def __init__(self, data=None, *args, **kwargs): super(CaptchaRegistrationForm, self).__init__( data, *args, **kwargs ) # Load data self.tampering = False if data is None or 'captcha_id' not in data: self.captcha = MathCaptcha() else: try: self.captcha = MathCaptcha.from_hash(data['captcha_id']) except ValueError: self.captcha = MathCaptcha() self.tampering = True # Set correct label self.fields['captcha'].label = pgettext( 'Question for a mathematics-based CAPTCHA, ' 'the %s is an arithmetic problem', 'What is %s?' ) % self.captcha.display self.fields['captcha_id'].initial = self.captcha.hashed
def __init__(self, request, data=None, *args, **kwargs): super(CaptchaForm, self).__init__(data, *args, **kwargs) self.fresh = False if (data is None or 'captcha_id' not in data or 'captcha' not in request.session or data['captcha_id'] not in request.session['captcha']): self.captcha = MathCaptcha() self.fresh = True request.session['captcha'] = {self.captcha.id: self.captcha.hashed} else: captcha_id = data['captcha_id'] self.captcha = MathCaptcha.from_hash( request.session['captcha'].pop(captcha_id), captcha_id ) # Set correct label self.fields['captcha'].label = pgettext( 'Question for a mathematics-based CAPTCHA, ' 'the %s is an arithmetic problem', 'What is %s?' ) % self.captcha.display self.fields['captcha_id'].initial = self.captcha.id
def __init__(self, request, data=None, *args, **kwargs): super(CaptchaForm, self).__init__(data, *args, **kwargs) self.fresh = False self.request = request if data is None or 'captcha' not in request.session: self.generate_captcha() self.fresh = True else: self.captcha = MathCaptcha.from_hash( request.session.pop('captcha'))
def __init__(self, request, form=None, data=None, *args, **kwargs): super(CaptchaForm, self).__init__(data, *args, **kwargs) self.fresh = False self.request = request self.form = form if data is None or 'captcha' not in request.session: self.generate_captcha() self.fresh = True else: self.captcha = MathCaptcha.from_hash( request.session.pop('captcha') )
def __init__(self, data=None, *args, **kwargs): super(CaptchaRegistrationForm, self).__init__(data, *args, **kwargs) # Load data self.tampering = False if data is None or 'captcha_id' not in data: self.captcha = MathCaptcha() else: try: self.captcha = MathCaptcha.from_hash(data['captcha_id']) except ValueError: self.captcha = MathCaptcha() self.tampering = True # Set correct label self.fields['captcha'].label = _('What is %s?') % self.captcha.display self.fields['captcha_id'].initial = self.captcha.hashed
def load_captcha(self, data): # Load data self.tampering = False if data is None or 'captcha_id' not in data: self.captcha = MathCaptcha() else: try: self.captcha = MathCaptcha.from_hash(data['captcha_id']) except ValueError: self.captcha = MathCaptcha() self.tampering = True # Set correct label self.fields['captcha'].label = pgettext( 'Question for a mathematics-based CAPTCHA, ' 'the %s is an arithmetic problem', 'What is %s?') % self.captcha.display self.fields['captcha_id'].initial = self.captcha.hashed
def __init__(self, data=None, *args, **kwargs): super(CaptchaRegistrationForm, self).__init__( data, *args, **kwargs ) # Load data self.tampering = False if data is None or 'captcha_id' not in data: self.captcha = MathCaptcha() else: try: self.captcha = MathCaptcha.from_hash(data['captcha_id']) except ValueError: self.captcha = MathCaptcha() self.tampering = True # Set correct label self.fields['captcha'].label = _('What is %s?') % self.captcha.display self.fields['captcha_id'].initial = self.captcha.hashed