25 |
25 |
26 |
26 |
27 from google.appengine.api import users |
27 from google.appengine.api import users |
28 |
28 |
29 from django import forms |
29 from django import forms |
|
30 from django.utils.translation import ugettext |
30 |
31 |
31 from soc.logic import validate |
32 from soc.logic import validate |
32 from soc.logic.models import site as site_logic |
33 from soc.logic.models import site as site_logic |
33 from soc.logic.models import user as user_logic |
34 from soc.logic.models import user as user_logic |
34 |
35 |
186 # call the Django URLField cleaning method to properly clean/validate this field |
187 # call the Django URLField cleaning method to properly clean/validate this field |
187 return forms.URLField.clean(self.fields[field_name], value) |
188 return forms.URLField.clean(self.fields[field_name], value) |
188 return wrapped |
189 return wrapped |
189 |
190 |
190 |
191 |
|
192 def clean_new_club_link_id(field_name, club_logic, club_app_logic): |
|
193 """Cleans the field_name value to check if it's a valid |
|
194 link_id for a new club. |
|
195 """ |
|
196 def wrapper(self): |
|
197 # validate the link_id |
|
198 club_link_id = clean_link_id(field_name)(self) |
|
199 |
|
200 # check if there is already an application with the given link_id |
|
201 fields = {'link_id': club_link_id, |
|
202 'state': ['accepted','ignored','needs review','completed']} |
|
203 club_app_entity = club_app_logic.logic.getForFields(fields, unique=True) |
|
204 |
|
205 if club_app_entity: |
|
206 raise forms.ValidationError( |
|
207 ugettext('This link ID is already in use, please specify another one')) |
|
208 |
|
209 # check if there is already a club with the given link_id |
|
210 fields['state'] = ['new', 'active', 'inactive'] |
|
211 club_entity = club_logic.logic.getForFields(fields, unique=True) |
|
212 |
|
213 if club_entity: |
|
214 raise forms.ValidationError( |
|
215 ugettext('This link ID is already in use, please specify another one')) |
|
216 |
|
217 return club_link_id |
|
218 return wrapper |
|
219 |
|
220 |
191 def validate_user_edit(link_id_field, account_field): |
221 def validate_user_edit(link_id_field, account_field): |
192 """Clean method for cleaning user edit form. |
222 """Clean method for cleaning user edit form. |
193 |
223 |
194 Raises ValidationError if: |
224 Raises ValidationError if: |
195 -Another User has the given email address as account |
225 -Another User has the given email address as account |