5
|
1 |
from django import forms
|
|
2 |
from django.utils.translation import ugettext_lazy as _
|
|
3 |
from content.models import Participant
|
|
4 |
from django.contrib.auth.models import User
|
|
5 |
|
|
6 |
class Participantform(forms.ModelForm):
|
|
7 |
class Meta:
|
|
8 |
model = Participant
|
|
9 |
|
|
10 |
class Registerform(forms.Form):
|
|
11 |
"""
|
|
12 |
Temporary Registration Form.
|
|
13 |
"""
|
|
14 |
PARTICIPANT_CATEGORY = (
|
|
15 |
('Student','Student'),
|
|
16 |
('Corporate Staff','Corporate Staff'),
|
|
17 |
('Teacher','Teacher'),
|
|
18 |
('Others','Others'),
|
|
19 |
)
|
|
20 |
username = forms.CharField(max_length=30,
|
|
21 |
label="User Name")
|
|
22 |
email = forms.EmailField(max_length=75,
|
|
23 |
label=u'Email address')
|
|
24 |
pass1 = forms.CharField(max_length=50,widget=forms.PasswordInput,
|
|
25 |
label=_("Enter New Password"),
|
|
26 |
)
|
|
27 |
pass2 = forms.CharField(max_length=50,widget=forms.PasswordInput,
|
|
28 |
label=_("Enter New Password Again"),
|
|
29 |
)
|
|
30 |
category = forms.ChoiceField(label=_("Category"),
|
|
31 |
choices=PARTICIPANT_CATEGORY)
|
|
32 |
organiztion = forms.CharField(max_length=200,
|
|
33 |
label=_("Organisation"),
|
|
34 |
required=False)
|
|
35 |
attending_conf = forms.BooleanField(label=_("Will you attend conference?"))
|
|
36 |
attending_tut = forms.BooleanField(label=_("Will you attend tutorial session?"),
|
|
37 |
required=False)
|
|
38 |
attending_sprint = forms.BooleanField(label=_("Will you attend sprint?"),
|
|
39 |
required=False)
|
|
40 |
|
|
41 |
def save(self):
|
|
42 |
'''To create a user and save additional information
|
|
43 |
related to user.
|
|
44 |
'''
|
|
45 |
profile=self.cleaned_data
|
|
46 |
new_user = User.objects.create_user(username=profile.get('username'),
|
|
47 |
password=profile.get('pass1'),
|
|
48 |
email=profile.get('email'))
|
|
49 |
participant = Participantform()
|
|
50 |
participant.username = profile.get('username')
|
|
51 |
participant.category = profile.get('category')
|
|
52 |
participant.organiztion = profile.get('organization')
|
|
53 |
participant.attending_conf = profile.get('attending_conf')
|
|
54 |
participant.attending_tut = profile.get('attending_tut')
|
|
55 |
participant.attending_sprint = profile.get('attending_sprint')
|
|
56 |
participant.save()
|
|
57 |
return new_user
|
|
58 |
|
|
59 |
class LoginForm(forms.Form):
|
|
60 |
username = forms.CharField(max_length=30, label=_(u'username'))
|
|
61 |
password = forms.CharField(max_length=50,widget=forms.PasswordInput,
|
|
62 |
label=_("Enter New Password")
|
|
63 |
)
|