app/soc/logic/cleaning.py
changeset 788 892877b7db07
parent 650 33b6dcae5615
child 837 bc1c951bf3a0
--- a/app/soc/logic/cleaning.py	Thu Jan 08 21:23:33 2009 +0000
+++ b/app/soc/logic/cleaning.py	Thu Jan 08 21:23:42 2009 +0000
@@ -26,6 +26,7 @@
 from django import forms
 
 from soc.logic import validate
+from soc.logic.models import user as user_logic
 
 
 def clean_new_link_id(logic):
@@ -56,6 +57,26 @@
   return link_id
 
 
+def clean_existing_user(field_name):
+  """Check if the field_name field is a valid user.
+  """
+
+  def wrapped(self):
+    link_id = self.cleaned_data.get(field_name).lower()
+  
+    if not validate.isLinkIdFormatValid(link_id):
+      raise forms.ValidationError("This link ID is in wrong format.")
+  
+    user_entity = user_logic.logic.getForFields({'link_id' : link_id}, unique=True)
+  
+    if not user_entity:
+      # user does not exist
+      raise forms.ValidationError("This user does not exist")
+  
+    return user_entity
+  return wrapped
+
+
 def clean_feed_url(self):
   feed_url = self.cleaned_data.get('feed_url')