author | nishanth |
Sun, 06 Jun 2010 01:26:59 +0530 | |
branch | anoop |
changeset 54 | 7515c2d1f5c5 |
parent 45 | 29d7d70c9273 |
child 56 | 7dfacad8adee |
permissions | -rw-r--r-- |
8 | 1 |
from django import forms |
2 |
||
19 | 3 |
from sage_days.sdi.models import Registrant, TOPICS_CHOICES |
41 | 4 |
from captcha.fields import CaptchaField |
8 | 5 |
|
6 |
class RegisterForm(forms.ModelForm): |
|
7 |
""" The form that is displayed to user. |
|
8 |
""" |
|
9 |
||
20
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
10 |
topics_interested = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=TOPICS_CHOICES, required=False) |
8 | 11 |
class Meta: |
12 |
model = Registrant |
|
45 | 13 |
exclude = ['priority_for_attending', 'selected_for_attending'] |
44 | 14 |
verification_code = CaptchaField() |
19 | 15 |
|
21 | 16 |
def clean_email(self): |
17 |
""" See if the user has already registered using the email. |
|
18 |
""" |
|
19 |
||
20 |
email = self.cleaned_data['email'].strip() |
|
21 |
try: |
|
22 |
Registrant.objects.get(email__iexact=email) |
|
23 |
raise forms.ValidationError("This email is already registered. Did you register earlier??") |
|
24 |
except Registrant.DoesNotExist: |
|
25 |
return email |
|
26 |
||
20
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
27 |
def clean_topics_interested(self): |
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
28 |
""" Join the choices using PIPE character and store them. |
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
29 |
""" |
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
30 |
|
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
31 |
topics = self.cleaned_data['topics_interested'] |
9db4ee082d4e
added topics choices and corresponding clean method
nishanth
parents:
19
diff
changeset
|
32 |
return "|".join(topics) |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
33 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
34 |
class SearchForm(forms.Form): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
35 |
""" Search form for filtering registrants. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
36 |
""" |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
37 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
38 |
topics_interested = forms.CharField(required=False, help_text=" Use numbers seperated by spaces and prefix a minus to exclude") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
39 |
knowledge_of_python = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
40 |
knowledge_of_sage = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
41 |
likeliness_of_attending = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
42 |
need_for_python_workshop = forms.BooleanField(required=False) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
43 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
44 |
def clean_topics_interested(self): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
45 |
""" split and return include list and exclude list |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
46 |
""" |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
47 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
48 |
include_list = [] |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
49 |
exclude_list = [] |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
50 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
51 |
topics = self.cleaned_data['topics_interested'] |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
52 |
for number in topics.split(): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
53 |
if number.startswith('-'): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
54 |
exclude_list.append(number[1:]) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
55 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
56 |
include_list.append(number) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
57 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
58 |
return (include_list, exclude_list) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
59 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
60 |
def clean_knowledge_of_python(self): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
61 |
""" if two numbers are given take start and stop. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
62 |
else take highest as default. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
63 |
""" |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
64 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
65 |
range_str = self.cleaned_data['knowledge_of_python'].strip() |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
66 |
if not range_str: |
25 | 67 |
return ("","") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
68 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
69 |
start_stop = range_str.split("-") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
70 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
71 |
if len(start_stop) == 1: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
72 |
if start_stop[0].isdigit(): |
25 | 73 |
return (start_stop[0], "") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
74 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
75 |
raise forms.ValidationError("Invalid range for knowledge of Python") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
76 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
77 |
elif len(start_stop) == 2: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
78 |
start, stop = start_stop |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
79 |
if start.isdigit() and stop.isdigit(): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
80 |
return (start, stop) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
81 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
82 |
raise forms.ValidationError("Invalid range for knowledge of Python") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
83 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
84 |
raise forms.ValidationError("Invalid range for knowledge of Python") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
85 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
86 |
def clean_knowledge_of_sage(self): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
87 |
""" if two numbers are given take start and stop. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
88 |
else take highest as default. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
89 |
""" |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
90 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
91 |
range_str = self.cleaned_data['knowledge_of_sage'].strip() |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
92 |
if not range_str: |
25 | 93 |
return ("","") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
94 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
95 |
start_stop = range_str.split("-") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
96 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
97 |
if len(start_stop) == 1: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
98 |
if start_stop[0].isdigit(): |
25 | 99 |
return (start_stop[0], "") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
100 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
101 |
raise forms.ValidationError("Invalid range for knowledge of Sage") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
102 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
103 |
elif len(start_stop) == 2: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
104 |
start, stop = start_stop |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
105 |
if start.isdigit() and stop.isdigit(): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
106 |
return (start, stop) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
107 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
108 |
raise forms.ValidationError("Invalid range for knowledge of Sage") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
109 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
110 |
raise forms.ValidationError("Invalid range for knowledge of Sage") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
111 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
112 |
def clean_likeliness_of_attending(self): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
113 |
""" if two numbers are given take start and stop. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
114 |
else take highest as default. |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
115 |
""" |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
116 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
117 |
range_str = self.cleaned_data['likeliness_of_attending'].strip() |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
118 |
if not range_str: |
25 | 119 |
return ("","") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
120 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
121 |
start_stop = range_str.split("-") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
122 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
123 |
if len(start_stop) == 1: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
124 |
if start_stop[0].isdigit(): |
25 | 125 |
return (start_stop[0], "") |
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
126 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
127 |
raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
128 |
|
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
129 |
elif len(start_stop) == 2: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
130 |
start, stop = start_stop |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
131 |
if start.isdigit() and stop.isdigit(): |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
132 |
return (start, stop) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
133 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
134 |
raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
135 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
136 |
raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
21
diff
changeset
|
137 |