app/soc/logic/cleaning.py
changeset 886 f5847f24c56e
parent 867 f4ea0da41915
child 898 adf5b7e98dcf
--- 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')