Added clean_existing_user_not_equal_to_current to clean the backup Administrator field in an application.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/cleaning.py Wed Jan 21 19:53:23 2009 +0000
+++ b/app/soc/logic/cleaning.py Wed Jan 21 20:25:07 2009 +0000
@@ -56,6 +56,25 @@
return user_entity
return wrapped
+def clean_existing_user_not_equal_to_current(field_name):
+ """Check if the field_name field is a valid user and is not
+ equal to the current user.
+ """
+
+ def wrapped(self):
+
+ clean_user_field = clean_existing_user(field_name)
+ user_entity = clean_user_field(self)
+
+ current_user_entity = user_logic.logic.getForCurrentAccount()
+
+ if user_entity.key() == current_user_entity.key():
+ # users are equal
+ raise forms.ValidationError("You cannot enter yourself here")
+
+ return user_entity
+ return wrapped
+
def clean_feed_url(self):
feed_url = self.cleaned_data.get('feed_url')
--- a/app/soc/views/models/club_app.py Wed Jan 21 19:53:23 2009 +0000
+++ b/app/soc/views/models/club_app.py Wed Jan 21 20:25:07 2009 +0000
@@ -78,7 +78,8 @@
'backup_admin_link_id': forms.CharField(
label=soc.models.club_app.ClubApplication.backup_admin.verbose_name
),
- 'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
+ 'clean_backup_admin_link_id':
+ cleaning.clean_existing_user_not_equal_to_current('backup_admin_link_id'),
}
patterns = [(r'^%(url_name)s/(?P<access_type>review)$',