X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/c518611f1b9da9f7960440df38bbc6f2e09e5821..631688575ca2c0a4bdfdf99bdd2470ee9630bc25:/contrib/waldo/forms.py?ds=inline diff --git a/contrib/waldo/forms.py b/contrib/waldo/forms.py index 50e1fa6..615d302 100644 --- a/contrib/waldo/forms.py +++ b/contrib/waldo/forms.py @@ -1,8 +1,11 @@ from datetime import date from django import forms +from django.conf import settings 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 LOGIN_FORM_KEY = 'this_is_the_login_form' @@ -17,6 +20,13 @@ class EmailInput(forms.TextInput): class RegistrationForm(UserCreationForm): email = forms.EmailField(widget=EmailInput) + try: + from recaptcha_django import ReCaptchaField + except ImportError: + pass + else: + if 'recaptcha_django.middleware.ReCaptchaMiddleware' in settings.MIDDLEWARE_CLASSES: + recaptcha = ReCaptchaField() def clean_username(self): username = self.cleaned_data['username'] @@ -46,4 +56,18 @@ class RegistrationForm(UserCreationForm): new_user = User.objects.create_user(username, email, password) new_user.is_active = False new_user.save() - return new_user \ No newline at end of file + return new_user + + +class UserAccountForm(forms.ModelForm): + 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) + + def __init__(self, user, *args, **kwargs): + kwargs['instance'] = user + super(UserAccountForm, self).__init__(*args, **kwargs) + + class Meta: + model = User + fields = ('first_name', 'last_name', 'email') \ No newline at end of file