forms.py 1.49 KB
Newer Older
1
from django.conf import settings
2 3
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm
4
from django.utils.translation import ugettext_lazy as _
5
from registration.forms import RegistrationForm as BaseRegistrationForm
Noe Nieto's avatar
Noe Nieto committed
6
from captcha.fields import CaptchaField
7

8
User = get_user_model()
9
username_title = _(settings.SITE_TITLE + " address")
10 11


12 13 14 15 16
class AuthenticationForm(BaseAuthenticationForm):
    # this currently has no effect

    def __init__(self, request=None, *args, **kwargs):
        super(AuthenticationForm, self).__init__(request, *args, **kwargs)
17
        self.fields[User.USERNAME_FIELD].label = username_title
18 19 20
        self.fields["password"].label = _("Passphrase")


21
class RegistrationForm(BaseRegistrationForm):
Noe Nieto's avatar
Noe Nieto committed
22
    captcha = CaptchaField()
23 24
    email = None  # override base definition to remove email field

25 26
    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
27
        self.fields[User.USERNAME_FIELD].label = username_title
28 29
        self.fields["password1"].label = _("Passphrase")
        self.fields["password2"].label = _("Passphrase confirmation")
30
        self.fields["password2"].help_text = _("Enter the same passphrase as before, for verification.")
31

32
    class Meta(BaseRegistrationForm.Meta):
33

34
        model = User
35 36

        # override base definition to remove email field
37
        fields = (
38 39
            User.USERNAME_FIELD,
            'password1',
40 41
            'password2',
        )