aboutsummaryrefslogtreecommitdiffstats
path: root/account/forms.py
blob: ca54711ba1cad2bb787e46c81b3e4b54d46337e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-

"""
account/forms.py for skaschool
"""

from django import forms
from registration.forms import RegistrationFormUniqueEmail
from django.utils.translation import ugettext_lazy as _

from account.models import UserProfile


class UserRegForm(RegistrationFormUniqueEmail):
    """
    based on 'django-registration' RegistrationFormUniqueEmail
    add fields 'realname', 'gender', 'institute' and 'captcha'
    """
    # XXX: keep consistent with GENDERS in 'models.UserProfile'
    GENDERS = (
        ('M', _("Male")),
        ('F', _("Female")),
        ('X', _("Secret")),
    )
    realname = forms.CharField(max_length=30, label=_("Name"))
    gender = forms.ChoiceField(choices=GENDERS, label=_("Gender"))
    institute = forms.CharField(max_length=100, label=_("Institute"))

    def __init__(self, *args, **kw):
        super(UserRegForm, self).__init__(*args, **kw)
        # order form fields
        self.fields.keyOrder = [
                'username',
                'email',
                'password1',
                'password2',
                'realname',
                'gender',
                'institute',
        ]


class UpdateProfileForm(forms.ModelForm):
    """
    ModelForm of 'UserProfile' used in 'UpdateProfileView'
    """
    # extra email field
    email = forms.EmailField(label=_("E-mail"))

    class Meta:
        model = UserProfile
        fields = ('realname', 'gender', 'institute')