tildetown-admin/ttadmin/common/forms.py

26 lines
942 B
Python
Raw Normal View History

2016-12-19 05:28:16 +00:00
from random import shuffle
2016-12-19 06:30:41 +00:00
from django.core.exceptions import ValidationError
2016-12-19 05:28:16 +00:00
from django.forms import ChoiceField
CAPTCHA_CHOICES = [('two', 'zorp borp'),
('three', 'quop bop'),
('four', 'NO, I AM NOT A ROBOT'),
('five', 'crackle zop'),
('six', '*rusty screech*'),
('seven', 'mother, give me legs')]
shuffle(CAPTCHA_CHOICES)
CAPTCHA_CHOICES.insert(0, ('one', 'beep boop'),)
NOT_A_ROBOT = 'four'
def validate_captcha(captcha):
if captcha != NOT_A_ROBOT:
raise ValidationError('Are you sure you are not a robot?')
class CaptchaField(ChoiceField):
def __init__(self):
super().__init__(choices=CAPTCHA_CHOICES,
label='are you a robot?',
help_text='pick the response that indicates whether or not you are a robot.',
validators=(validate_captcha,))