# HG changeset patch # User Lennard de Rijk # Date 1233315968 0 # Node ID b8018d7a9f2343344a8f9bb063e5351dfeb59d95 # Parent 946adb594793698b8baf698da8349fba891bd53c Moved clean_club_app_link_id to cleaning. This method is now also used by the club create_form. Which means that you cannot create a new club with an already reserved link_id until the club application has been rejected. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r 946adb594793 -r b8018d7a9f23 app/soc/logic/cleaning.py --- a/app/soc/logic/cleaning.py Fri Jan 30 11:30:43 2009 +0000 +++ b/app/soc/logic/cleaning.py Fri Jan 30 11:46:08 2009 +0000 @@ -27,6 +27,7 @@ from google.appengine.api import users from django import forms +from django.utils.translation import ugettext from soc.logic import validate from soc.logic.models import site as site_logic @@ -188,6 +189,35 @@ return wrapped +def clean_new_club_link_id(field_name, club_logic, club_app_logic): + """Cleans the field_name value to check if it's a valid + link_id for a new club. + """ + def wrapper(self): + # validate the link_id + club_link_id = 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_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 + + def validate_user_edit(link_id_field, account_field): """Clean method for cleaning user edit form. diff -r 946adb594793 -r b8018d7a9f23 app/soc/views/models/club.py --- a/app/soc/views/models/club.py Fri Jan 30 11:30:43 2009 +0000 +++ b/app/soc/views/models/club.py Fri Jan 30 11:46:08 2009 +0000 @@ -28,6 +28,7 @@ from django import http from django import forms +from soc.logic import cleaning from soc.logic import dicts from soc.logic.models import user as user_logic from soc.logic.models import club_app as club_app_logic @@ -90,9 +91,14 @@ new_params['sidebar_additional'] = [ ('/' + new_params['url_name'] + '/apply_member', 'Join a Club', 'apply_member'),] + new_params['create_extra_dynafields'] = { + 'clean_link_id': cleaning.clean_new_club_link_id('link_id', + club_logic, club_app_logic) + } new_params['edit_extra_dynafields'] = { 'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(), required=False), + 'clean_link_id': cleaning.clean_link_id('link_id') } params = dicts.merge(params, new_params) @@ -102,7 +108,8 @@ # create and store the special form for applicants updated_fields = { 'link_id': forms.CharField(widget=widgets.ReadOnlyInput(), - required=False)} + required=False), + 'clean_link_id': cleaning.clean_link_id('link_id')} applicant_create_form = dynaform.extendDynaForm( dynaform = self._params['create_form'], diff -r 946adb594793 -r b8018d7a9f23 app/soc/views/models/club_app.py --- a/app/soc/views/models/club_app.py Fri Jan 30 11:30:43 2009 +0000 +++ b/app/soc/views/models/club_app.py Fri Jan 30 11:46:08 2009 +0000 @@ -82,7 +82,8 @@ ), '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') + 'clean_link_id': cleaning.clean_new_club_link_id('link_id', + model_logic.club, club_app_logic) } new_params['edit_extra_dynafields'] = { @@ -343,34 +344,6 @@ # 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()