8 from registration.models import RegistrationProfile |
8 from registration.models import RegistrationProfile |
9 |
9 |
10 from pytask.utils import make_key |
10 from pytask.utils import make_key |
11 from pytask.profile.models import GENDER_CHOICES, Profile |
11 from pytask.profile.models import GENDER_CHOICES, Profile |
12 |
12 |
13 class RegistrationFormCustom(RegistrationFormUniqueEmail): |
13 class CustomRegistrationForm(RegistrationFormUniqueEmail): |
14 """Used instead of RegistrationForm used by default django-registration |
14 """Used instead of RegistrationForm used by default django-registration |
15 backend, this adds aboutme, dob, gender, address, phonenum to the default |
15 backend, this adds aboutme, dob, gender, address, phonenum to the default |
16 django-registration RegistrationForm""" |
16 django-registration RegistrationForm""" |
17 |
17 |
18 aboutme = forms.TextField(required=True, max_length=1000, label=u"About Me", |
18 aboutme = forms.CharField(required=True, max_length=1000, label=u"About Me", |
19 help_text="A write up about yourself to aid the\ |
19 help_text="A write up about yourself to aid the\ |
20 reviewer in judging your eligibility for a task.\ |
20 reviewer in judging your eligibility for a task.\ |
21 It can have your educational background, CGPA,\ |
21 It can have your educational background, CGPA,\ |
22 field of interests etc.," |
22 field of interests etc.," |
23 ) |
23 ) |
24 |
24 |
25 |
25 |
26 dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth') |
26 dob = forms.DateField(help_text = "YYYY-MM-DD", required=True, label=u'date of birth') |
27 gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender') |
27 gender = forms.ChoiceField(choices = GENDER_CHOICES, required=True, label=u'gender') |
28 |
28 |
29 address = forms.TextField(required=True, max_length=200, help_text="This \ |
29 address = forms.CharField(required=True, max_length=200, help_text="This \ |
30 information will be used while sending DD/Cheque") |
30 information will be used while sending DD/Cheque") |
31 phonenum = forms.TextField(required=True, max_length=10. label="Phone |
31 phonenum = forms.CharField(required=True, max_length=10, |
32 Number") |
32 label="Phone Number") |
33 |
33 |
34 def clean_aboutme(self): |
34 def clean_aboutme(self): |
35 """ Empty not allowed """ |
35 """ Empty not allowed """ |
36 |
36 |
37 data = self.cleaned_data['aboutme'] |
37 data = self.cleaned_data['aboutme'] |
38 if not data.strip(): |
38 if not data.strip(): |
39 raise forms.ValidationError("Please write something about |
39 raise forms.ValidationError("Please write something about\ |
40 yourself") |
40 yourself") |
41 |
41 |
42 return data |
42 return data |
43 |
43 |
44 def clean_address(self): |
44 def clean_address(self): |
72 |
72 |
73 new_profile = Profile(user=new_user, |
73 new_profile = Profile(user=new_user, |
74 aboutme=self.cleaned_data['aboutme'], |
74 aboutme=self.cleaned_data['aboutme'], |
75 dob=self.cleaned_data['dob'], |
75 dob=self.cleaned_data['dob'], |
76 gender=self.cleaned_data['gender'], |
76 gender=self.cleaned_data['gender'], |
77 address=self.cleaned_data['address'] |
77 address=self.cleaned_data['address'], |
78 phonenum=self.cleaned_data['phonenum'], |
78 phonenum=self.cleaned_data['phonenum'], |
79 uniq_key=make_key(Profile), |
79 uniq_key=make_key(Profile), |
80 ) |
80 ) |
81 new_profile.save() |
81 new_profile.save() |
82 |
82 |