Added removal of an existing group application when someone else is applying.
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 03 Feb 2009 14:19:51 +0000
changeset 1202 8060f33a164f
parent 1201 0a4c1af700a0
child 1203 38225f2ad3a6
Added removal of an existing group application when someone else is applying. This makes sure that the fields we do not collect via the form also get wiped when a rejected application is being redone by someone else. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/models/group_app.py
--- a/app/soc/views/models/group_app.py	Tue Feb 03 13:50:41 2009 +0000
+++ b/app/soc/views/models/group_app.py	Tue Feb 03 14:19:51 2009 +0000
@@ -110,10 +110,22 @@
     """See base.View._editPost().
     """
 
-    fields['backup_admin'] = fields['backup_admin_link_id']
+    if not entity:
+      # creating a new group application
+      key_fields =  self._logic.getKeyFieldsFromFields(fields)
+      group_app_entity = self._logic.getForFields(key_fields, unique=True)
+
+      user_entity = user_logic.logic.getForCurrentAccount()
 
-    if not entity:
-      fields['applicant'] = user_logic.logic.getForCurrentAccount()
+      if group_app_entity.applicant.key() != user_entity.key():
+        # someone else is applying remove the existing group application
+        group_app_logic.logic.delete(group_app_entity)
+
+      # set the applicant field to the current user
+      fields['applicant'] = user_entity
+
+    #set the backup_admin field with the cleaned link_id
+    fields['backup_admin'] = fields['backup_admin_link_id']
 
     # the application has either been created or edited so
     # the status needs to be set accordingly