diff -r d533408811ba -r 81cf69225a24 app/soc/views/models/club_app.py --- a/app/soc/views/models/club_app.py Fri Jan 30 11:15:26 2009 +0000 +++ b/app/soc/views/models/club_app.py Fri Jan 30 11:16:48 2009 +0000 @@ -30,6 +30,7 @@ from soc.logic import cleaning from soc.logic import dicts from soc.logic.helper import notifications +from soc.logic import models as model_logic from soc.logic.models import club_app as club_app_logic from soc.logic.models import user as user_logic from soc.views import helper @@ -81,6 +82,7 @@ ), 'clean_backup_admin_link_id': cleaning.clean_users_not_same('backup_admin_link_id'), + 'clean_link_id' : self.clean_club_app_link_id('link_id') } new_params['edit_extra_dynafields'] = { @@ -341,6 +343,34 @@ # call the _list method from base to display the list return self._list(request, params, contents, page_name) + def clean_club_app_link_id(self, field_name): + """Cleans the link_id in the club application form + """ + def wrapper(self): + # validate the link_id + club_link_id = cleaning.clean_link_id(field_name)(self) + + # check if there is already an application with the given link_id + fields = {'link_id': club_link_id, + 'state': ['accepted','ignored','needs review','completed']} + club_app_entity = club_app_logic.logic.getForFields(fields, unique=True) + + if club_app_entity: + raise forms.ValidationError( + ugettext('This link ID is already in use, please specify another one')) + + # check if there is already a club with the given link_id + fields['state'] = ['new', 'active', 'inactive'] + club_logic = model_logic.club + club_entity = club_logic.logic.getForFields(fields, unique=True) + + if club_entity: + raise forms.ValidationError( + ugettext('This link ID is already in use, please specify another one')) + + return club_link_id + return wrapper + view = View()