25 """ Join the choices using PIPE character and store them. |
25 """ Join the choices using PIPE character and store them. |
26 """ |
26 """ |
27 |
27 |
28 topics = self.cleaned_data['topics_interested'] |
28 topics = self.cleaned_data['topics_interested'] |
29 return "|".join(topics) |
29 return "|".join(topics) |
|
30 |
|
31 class SearchForm(forms.Form): |
|
32 """ Search form for filtering registrants. |
|
33 """ |
|
34 |
|
35 topics_interested = forms.CharField(required=False, help_text=" Use numbers seperated by spaces and prefix a minus to exclude") |
|
36 knowledge_of_python = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
|
37 knowledge_of_sage = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
|
38 likeliness_of_attending = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen") |
|
39 need_for_python_workshop = forms.BooleanField(required=False) |
|
40 |
|
41 def clean_topics_interested(self): |
|
42 """ split and return include list and exclude list |
|
43 """ |
|
44 |
|
45 include_list = [] |
|
46 exclude_list = [] |
|
47 |
|
48 topics = self.cleaned_data['topics_interested'] |
|
49 for number in topics.split(): |
|
50 if number.startswith('-'): |
|
51 exclude_list.append(number[1:]) |
|
52 else: |
|
53 include_list.append(number) |
|
54 |
|
55 return (include_list, exclude_list) |
|
56 |
|
57 def clean_knowledge_of_python(self): |
|
58 """ if two numbers are given take start and stop. |
|
59 else take highest as default. |
|
60 """ |
|
61 |
|
62 range_str = self.cleaned_data['knowledge_of_python'].strip() |
|
63 if not range_str: |
|
64 return (1,5) |
|
65 |
|
66 start_stop = range_str.split("-") |
|
67 |
|
68 if len(start_stop) == 1: |
|
69 if start_stop[0].isdigit(): |
|
70 print "only one" |
|
71 return (start_stop[0], 5) |
|
72 else: |
|
73 raise forms.ValidationError("Invalid range for knowledge of Python") |
|
74 |
|
75 elif len(start_stop) == 2: |
|
76 start, stop = start_stop |
|
77 if start.isdigit() and stop.isdigit(): |
|
78 return (start, stop) |
|
79 else: |
|
80 raise forms.ValidationError("Invalid range for knowledge of Python") |
|
81 else: |
|
82 raise forms.ValidationError("Invalid range for knowledge of Python") |
|
83 |
|
84 def clean_knowledge_of_sage(self): |
|
85 """ if two numbers are given take start and stop. |
|
86 else take highest as default. |
|
87 """ |
|
88 |
|
89 range_str = self.cleaned_data['knowledge_of_sage'].strip() |
|
90 if not range_str: |
|
91 return (1,5) |
|
92 |
|
93 start_stop = range_str.split("-") |
|
94 |
|
95 if len(start_stop) == 1: |
|
96 if start_stop[0].isdigit(): |
|
97 print "only one" |
|
98 return (start_stop[0], 5) |
|
99 else: |
|
100 raise forms.ValidationError("Invalid range for knowledge of Sage") |
|
101 |
|
102 elif len(start_stop) == 2: |
|
103 start, stop = start_stop |
|
104 if start.isdigit() and stop.isdigit(): |
|
105 return (start, stop) |
|
106 else: |
|
107 raise forms.ValidationError("Invalid range for knowledge of Sage") |
|
108 else: |
|
109 raise forms.ValidationError("Invalid range for knowledge of Sage") |
|
110 |
|
111 def clean_likeliness_of_attending(self): |
|
112 """ if two numbers are given take start and stop. |
|
113 else take highest as default. |
|
114 """ |
|
115 |
|
116 range_str = self.cleaned_data['likeliness_of_attending'].strip() |
|
117 if not range_str: |
|
118 return (1,5) |
|
119 |
|
120 start_stop = range_str.split("-") |
|
121 |
|
122 if len(start_stop) == 1: |
|
123 if start_stop[0].isdigit(): |
|
124 print "only one" |
|
125 return (start_stop[0], 5) |
|
126 else: |
|
127 raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
|
128 |
|
129 elif len(start_stop) == 2: |
|
130 start, stop = start_stop |
|
131 if start.isdigit() and stop.isdigit(): |
|
132 return (start, stop) |
|
133 else: |
|
134 raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
|
135 else: |
|
136 raise forms.ValidationError("Invalid range for Likeliness of attending the workshop") |
|
137 |