|
1 |
|
2 import os |
|
3 import PIL |
|
4 |
|
5 from django import forms |
|
6 |
|
7 from registration.forms import RegistrationFormUniqueEmail |
|
8 from registration.models import RegistrationProfile |
|
9 |
|
10 from pytask.utils import make_key |
|
11 from pytask.profile.models import GENDER_CHOICES, Profile |
|
12 |
|
13 class RegistrationFormCustom(RegistrationFormUniqueEmail): |
|
14 """Used instead of RegistrationForm used by default django-registration |
|
15 backend, this adds aboutme, dob, gender, address, phonenum to the default |
|
16 django-registration RegistrationForm""" |
|
17 |
|
18 aboutme = forms.TextField(required=True, max_length=1000, label=u"About Me", |
|
19 help_text="A write up about yourself to aid the\ |
|
20 reviewer in judging your eligibility for a task.\ |
|
21 It can have your educational background, CGPA,\ |
|
22 field of interests etc.," |
|
23 ) |
|
24 |
|
25 |
|
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') |
|
28 |
|
29 address = forms.TextField(required=True, max_length=200, help_text="This \ |
|
30 information will be used while sending DD/Cheque") |
|
31 phonenum = forms.TextField(required=True, max_length=10. label="Phone |
|
32 Number") |
|
33 |
|
34 def clean_aboutme(self): |
|
35 """ Empty not allowed """ |
|
36 |
|
37 data = self.cleaned_data['aboutme'] |
|
38 if not data.strip(): |
|
39 raise forms.ValidationError("Please write something about |
|
40 yourself") |
|
41 |
|
42 return data |
|
43 |
|
44 def clean_address(self): |
|
45 """ Empty not allowed """ |
|
46 |
|
47 data = self.cleaned_data['address'] |
|
48 if not data.strip(): |
|
49 raise forms.ValidationError("Please enter an address") |
|
50 |
|
51 return data |
|
52 |
|
53 def clean_phonenum(self): |
|
54 """ should be of 10 digits """ |
|
55 |
|
56 data = self.cleaned_data['phonenum'] |
|
57 |
|
58 if (not data.strip()) or |
|
59 (data.strip("1234567890")) or |
|
60 (len(data)!= 10): |
|
61 raise forms.ValidationError("This is not a valid phone number") |
|
62 |
|
63 return data |
|
64 |
|
65 |
|
66 def save(self,profile_callback=None): |
|
67 |
|
68 new_user = RegistrationProfile.objects.create_inactive_user( |
|
69 username=self.cleaned_data['username'], |
|
70 password=self.cleaned_data['password1'], |
|
71 email=self.cleaned_data['email']) |
|
72 |
|
73 new_profile = Profile(user=new_user, |
|
74 aboutme=self.cleaned_data['aboutme'], |
|
75 dob=self.cleaned_data['dob'], |
|
76 gender=self.cleaned_data['gender'], |
|
77 address=self.cleaned_data['address'] |
|
78 phonenum=self.cleaned_data['phonenum'], |
|
79 ) |
|
80 new_profile.save() |
|
81 |
|
82 return new_user |
|
83 |