author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 01 Feb 2011 19:38:41 +0530 | |
changeset 550 | a606a40584f7 |
parent 520 | 958eb8854b63 |
permissions | -rw-r--r-- |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
1 |
import os |
520
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
2 |
import re |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
3 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
4 |
from django import forms |
520
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
5 |
from django.utils.translation import ugettext |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
6 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
7 |
from registration.forms import RegistrationFormUniqueEmail |
520
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
8 |
from registration.forms import attrs_dict |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
9 |
from registration.models import RegistrationProfile |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
10 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
11 |
from pytask.profile.models import GENDER_CHOICES, Profile |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
12 |
|
254 | 13 |
class CustomRegistrationForm(RegistrationFormUniqueEmail): |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
14 |
"""Used instead of RegistrationForm used by default django-registration |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
15 |
backend, this adds aboutme, dob, gender, address, phonenum to the default |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
16 |
django-registration RegistrationForm""" |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
17 |
|
520
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
18 |
# overriding only this field from the parent Form Class since we |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
19 |
# don't like the restriction imposed by the registration app on username |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
20 |
# GMail has more or less set the standard for user names |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
21 |
username = forms.CharField( |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
22 |
max_length=30, widget=forms.TextInput(attrs=attrs_dict), |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
23 |
label=ugettext('Username'), help_text='Username can contain alphabet, ' |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
24 |
'numbers or special characters underscore (_) and (.)') |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
25 |
|
300
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
26 |
full_name = forms.CharField(required=True, max_length=50, |
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
27 |
label="Name as on your bank account", |
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
28 |
help_text="Any DD/Cheque will be issued on \ |
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
29 |
this name") |
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
30 |
|
319
70726699ca80
now the text area is displayed in a more elegant way
Nishanth Amuluru <nishanth@fossee.in>
parents:
315
diff
changeset
|
31 |
aboutme = forms.CharField(required=True, widget=forms.Textarea, |
70726699ca80
now the text area is displayed in a more elegant way
Nishanth Amuluru <nishanth@fossee.in>
parents:
315
diff
changeset
|
32 |
max_length=1000, label=u"About Me", |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
33 |
help_text="A write up about yourself to aid the\ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
34 |
reviewer in judging your eligibility for a task.\ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
35 |
It can have your educational background, CGPA,\ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
36 |
field of interests etc.," |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
37 |
) |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
38 |
|
478
863dba311ba2
Fix the styling and modify the help text to calendar field to use the conventional format.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
468
diff
changeset
|
39 |
|
863dba311ba2
Fix the styling and modify the help text to calendar field to use the conventional format.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
468
diff
changeset
|
40 |
dob = forms.DateField(help_text = "yyyy-mm-dd", required=True, |
863dba311ba2
Fix the styling and modify the help text to calendar field to use the conventional format.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
468
diff
changeset
|
41 |
label=u'Date of Birth') |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
42 |
|
463
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
43 |
gender = forms.ChoiceField(choices = GENDER_CHOICES, |
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
44 |
required=True, label=u'Gender') |
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
45 |
|
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
46 |
address = forms.CharField( |
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
47 |
required=True, max_length=200, widget=forms.Textarea, |
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
48 |
help_text="This information will be used while sending DD/Cheque") |
c7c595c0bed3
Make changes to the code style so that it is consistent across the code base.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
412
diff
changeset
|
49 |
|
254 | 50 |
phonenum = forms.CharField(required=True, max_length=10, |
51 |
label="Phone Number") |
|
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
52 |
|
520
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
53 |
def clean_username(self): |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
54 |
"""Add additional cleaner for username than the parent class |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
55 |
supplied cleaner. |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
56 |
""" |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
57 |
|
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
58 |
username = self.cleaned_data['username'] |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
59 |
|
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
60 |
# None of the regular expression works better than this custom |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
61 |
# username check. |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
62 |
if not re.match(r'^\w+', username): |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
63 |
raise forms.ValidationError( |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
64 |
ugettext('Username can start only with an alphabet or a number')) |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
65 |
elif not re.search(r'\w+$', username): |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
66 |
raise forms.ValidationError( |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
67 |
ugettext('Username can end only with an alphabet or a number')) |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
68 |
elif re.search(r'\.\.+', username): |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
69 |
raise forms.ValidationError( |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
70 |
ugettext('Username cannot not have consecutive periods(.)')) |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
71 |
|
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
72 |
return super(CustomRegistrationForm, self).clean_username() |
958eb8854b63
Override the username field provided by Registration app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
478
diff
changeset
|
73 |
|
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
74 |
def clean_aboutme(self): |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
75 |
""" Empty not allowed """ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
76 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
77 |
data = self.cleaned_data['aboutme'] |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
78 |
if not data.strip(): |
254 | 79 |
raise forms.ValidationError("Please write something about\ |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
80 |
yourself") |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
81 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
82 |
return data |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
83 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
84 |
def clean_address(self): |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
85 |
""" Empty not allowed """ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
86 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
87 |
data = self.cleaned_data['address'] |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
88 |
if not data.strip(): |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
89 |
raise forms.ValidationError("Please enter an address") |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
90 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
91 |
return data |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
92 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
93 |
def clean_phonenum(self): |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
94 |
""" should be of 10 digits """ |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
95 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
96 |
data = self.cleaned_data['phonenum'] |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
97 |
|
254 | 98 |
if (not data.strip()) or \ |
99 |
(data.strip("1234567890")) or \ |
|
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
100 |
(len(data)!= 10): |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
101 |
raise forms.ValidationError("This is not a valid phone number") |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
102 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
103 |
return data |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
104 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
105 |
|
466
8ecd503354de
Fix the style as per PEP8 guidelines.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
463
diff
changeset
|
106 |
def save(self, profile_callback=None): |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
107 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
108 |
new_user = RegistrationProfile.objects.create_inactive_user( |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
109 |
username=self.cleaned_data['username'], |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
110 |
password=self.cleaned_data['password1'], |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
111 |
email=self.cleaned_data['email']) |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
112 |
|
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
113 |
new_profile = Profile(user=new_user, |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
114 |
aboutme=self.cleaned_data['aboutme'], |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
115 |
dob=self.cleaned_data['dob'], |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
116 |
gender=self.cleaned_data['gender'], |
254 | 117 |
address=self.cleaned_data['address'], |
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
118 |
phonenum=self.cleaned_data['phonenum'], |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
119 |
) |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
120 |
new_profile.save() |
466
8ecd503354de
Fix the style as per PEP8 guidelines.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
463
diff
changeset
|
121 |
|
252
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
122 |
return new_user |
5a92fcacdd5a
Created a form for user creation
Nishanth Amuluru <nishanth@fossee.in>
parents:
247
diff
changeset
|
123 |
|
466
8ecd503354de
Fix the style as per PEP8 guidelines.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
463
diff
changeset
|
124 |
|
312
a8fbe291385c
Created a form for creating profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
311
diff
changeset
|
125 |
class CreateProfileForm(forms.ModelForm): |
a8fbe291385c
Created a form for creating profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
311
diff
changeset
|
126 |
|
a8fbe291385c
Created a form for creating profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
311
diff
changeset
|
127 |
class Meta: |
a8fbe291385c
Created a form for creating profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
311
diff
changeset
|
128 |
model = Profile |
468
e5f8ea40369c
Replace the occurence of role to rights.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
467
diff
changeset
|
129 |
exclude = ['pynts', 'role'] |
312
a8fbe291385c
Created a form for creating profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
311
diff
changeset
|
130 |
|
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
254
diff
changeset
|
131 |
class EditProfileForm(forms.ModelForm): |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
254
diff
changeset
|
132 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
254
diff
changeset
|
133 |
class Meta: |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
254
diff
changeset
|
134 |
model = Profile |
300
ce5f3cdbd545
Used the new field in forms
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
135 |
fields = ['full_name', 'aboutme', 'gender', 'dob', 'address', 'phonenum'] |
311
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
136 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
137 |
def clean_aboutme(self): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
138 |
""" Empty not allowed """ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
139 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
140 |
data = self.cleaned_data['aboutme'] |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
141 |
if not data.strip(): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
142 |
raise forms.ValidationError("Please write something about\ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
143 |
yourself") |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
144 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
145 |
return data |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
146 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
147 |
def clean_address(self): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
148 |
""" Empty not allowed """ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
149 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
150 |
data = self.cleaned_data['address'] |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
151 |
if not data.strip(): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
152 |
raise forms.ValidationError("Please enter an address") |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
153 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
154 |
return data |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
155 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
156 |
def clean_phonenum(self): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
157 |
""" should be of 10 digits """ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
158 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
159 |
data = self.cleaned_data['phonenum'] |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
160 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
161 |
if (not data.strip()) or \ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
162 |
(data.strip("1234567890")) or \ |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
163 |
(len(data)!= 10): |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
164 |
raise forms.ValidationError("This is not a valid phone number") |
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
165 |
|
de27bb39375f
Added clean methods to edit profile form
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
166 |
return data |