app/soc/logic/cleaning.py
changeset 1083 b8018d7a9f23
parent 1079 be1aacb33b0f
child 1085 0afbdd0905ef
--- 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.