app/soc/views/models/notification.py
changeset 788 892877b7db07
parent 763 c31a2eb14d6d
child 799 30a912906a57
--- a/app/soc/views/models/notification.py	Thu Jan 08 21:23:33 2009 +0000
+++ b/app/soc/views/models/notification.py	Thu Jan 08 21:23:42 2009 +0000
@@ -27,6 +27,7 @@
 from django import forms
 from django.utils.translation import ugettext_lazy
 
+from soc.logic import cleaning
 from soc.logic import dicts
 from soc.logic import validate
 from soc.models import notification as notification_model
@@ -63,21 +64,7 @@
     # exclude the necessary fields from the form
     exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']
 
-  def clean_to_user(self):
-    """Check if the to_user field has been filled in correctly.
-    """
-    link_id = self.cleaned_data.get('to_user').lower()
-
-    if not validate.isLinkIdFormatValid(link_id):
-      raise forms.ValidationError("This link ID is in wrong format.")
-
-    to_user = user_logic.logic.getForFields({'link_id' : link_id}, unique=True)
-
-    if not to_user:
-      # user does not exist
-      raise forms.ValidationError("This user does not exist")
-
-    return link_id
+  clean_to_user = cleaning.clean_existing_user('to_user')
 
 
 class View(base.View):
@@ -157,13 +144,10 @@
     # get the current user
     current_user = user_logic.logic.getForCurrentAccount()
 
-    to_user = user_logic.logic.getForFields(
-        {'link_id' : fields['to_user']}, unique=True)
-
     fields['link_id'] = '%i' % (time.time())
-    fields['scope'] = to_user
+    fields['scope'] = fields['to_user']
     fields['from_user'] = current_user
-    fields['scope_path'] = fields['to_user']
+    fields['scope_path'] = fields['to_user'].link_id
 
   def _editSeed(self, request, seed):
     """Checks if scope_path is seeded and puts it into to_user.