X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/ed6b9876b7abff0b2dc6266d6f769c319f358a9c..1a56dac4a9131e6c453ef496fe8a496969e8ff0d:/philo/contrib/waldo/forms.py diff --git a/philo/contrib/waldo/forms.py b/philo/contrib/waldo/forms.py index 2ee64d0..eb53598 100644 --- a/philo/contrib/waldo/forms.py +++ b/philo/contrib/waldo/forms.py @@ -1,4 +1,5 @@ from datetime import date + from django import forms from django.conf import settings from django.contrib.auth import authenticate @@ -6,14 +7,23 @@ from django.contrib.auth.forms import AuthenticationForm, UserCreationForm from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ + from philo.contrib.waldo.tokens import REGISTRATION_TIMEOUT_DAYS class EmailInput(forms.TextInput): + """Displays an HTML5 email input on browsers which support it and a normal text input on other browsers.""" input_type = 'email' class RegistrationForm(UserCreationForm): + """ + Handles user registration. If :mod:`recaptcha_django` is installed on the system and :class:`recaptcha_django.middleware.ReCaptchaMiddleware` is in :setting:`settings.MIDDLEWARE_CLASSES`, then a recaptcha field will automatically be added to the registration form. + + .. seealso:: `recaptcha-django `_ + + """ + #: An :class:`EmailField` using the :class:`EmailInput` widget. email = forms.EmailField(widget=EmailInput) try: from recaptcha_django import ReCaptchaField @@ -55,6 +65,7 @@ class RegistrationForm(UserCreationForm): class UserAccountForm(forms.ModelForm): + """Handles a user's account - by default, :attr:`auth.User.first_name`, :attr:`auth.User.last_name`, :attr:`auth.User.email`.""" first_name = User._meta.get_field('first_name').formfield(required=True) last_name = User._meta.get_field('last_name').formfield(required=True) email = User._meta.get_field('email').formfield(required=True, widget=EmailInput) @@ -69,6 +80,7 @@ class UserAccountForm(forms.ModelForm): class WaldoAuthenticationForm(AuthenticationForm): + """Handles user authentication. Checks that the user has not mistakenly entered their email address (like :class:`django.contrib.admin.forms.AdminAuthenticationForm`) but does not require that the user be staff.""" ERROR_MESSAGE = _("Please enter a correct username and password. Note that both fields are case-sensitive.") def clean(self): @@ -92,11 +104,4 @@ class WaldoAuthenticationForm(AuthenticationForm): elif not self.user_cache.is_active: raise ValidationError(message) self.check_for_test_cookie() - return self.cleaned_data - - def check_for_test_cookie(self): - # This method duplicates the Django 1.3 AuthenticationForm method. - if self.request and not self.request.session.test_cookie_worked(): - raise forms.ValidationError( - _("Your Web browser doesn't appear to have cookies enabled. " - "Cookies are required for logging in.")) \ No newline at end of file + return self.cleaned_data \ No newline at end of file