def clean(self, value): super(AnimalCaptchaField, self).clean(value) response, value[1] = (value[1] or '').strip().lower(), '' AnimalCaptchaStore.remove_expired() try: AnimalCaptchaStore.objects.get(response=response, hashkey=value[0], expiration__gt=datetime.datetime.now()).delete() except AnimalCaptchaStore.DoesNotExist: raise ValidationError(getattr(self, 'error_messages', {}).get('invalid', ugettext_lazy('Invalid animal captcha!'))) return value
def render(self, name, value, attrs=None): key = AnimalCaptchaStore.generate_key() self._value, self._key, self.id_ = [key, u''], key, self.build_attrs(attrs).get('id', None) return super(AnimalCaptchaTextInput, self).render(name, self._value, attrs=attrs)