app/soc/views/models/notification.py
changeset 788 892877b7db07
parent 763 c31a2eb14d6d
child 799 30a912906a57
equal deleted inserted replaced
787:63d7f170b63c 788:892877b7db07
    25 import time
    25 import time
    26 
    26 
    27 from django import forms
    27 from django import forms
    28 from django.utils.translation import ugettext_lazy
    28 from django.utils.translation import ugettext_lazy
    29 
    29 
       
    30 from soc.logic import cleaning
    30 from soc.logic import dicts
    31 from soc.logic import dicts
    31 from soc.logic import validate
    32 from soc.logic import validate
    32 from soc.models import notification as notification_model
    33 from soc.models import notification as notification_model
    33 from soc.views import helper
    34 from soc.views import helper
    34 from soc.views.helper import access
    35 from soc.views.helper import access
    61     model = notification_model.Notification
    62     model = notification_model.Notification
    62 
    63 
    63     # exclude the necessary fields from the form
    64     # exclude the necessary fields from the form
    64     exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']
    65     exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']
    65 
    66 
    66   def clean_to_user(self):
    67   clean_to_user = cleaning.clean_existing_user('to_user')
    67     """Check if the to_user field has been filled in correctly.
       
    68     """
       
    69     link_id = self.cleaned_data.get('to_user').lower()
       
    70 
       
    71     if not validate.isLinkIdFormatValid(link_id):
       
    72       raise forms.ValidationError("This link ID is in wrong format.")
       
    73 
       
    74     to_user = user_logic.logic.getForFields({'link_id' : link_id}, unique=True)
       
    75 
       
    76     if not to_user:
       
    77       # user does not exist
       
    78       raise forms.ValidationError("This user does not exist")
       
    79 
       
    80     return link_id
       
    81 
    68 
    82 
    69 
    83 class View(base.View):
    70 class View(base.View):
    84   """View methods for the Notification model.
    71   """View methods for the Notification model.
    85   """
    72   """
   155     """
   142     """
   156 
   143 
   157     # get the current user
   144     # get the current user
   158     current_user = user_logic.logic.getForCurrentAccount()
   145     current_user = user_logic.logic.getForCurrentAccount()
   159 
   146 
   160     to_user = user_logic.logic.getForFields(
       
   161         {'link_id' : fields['to_user']}, unique=True)
       
   162 
       
   163     fields['link_id'] = '%i' % (time.time())
   147     fields['link_id'] = '%i' % (time.time())
   164     fields['scope'] = to_user
   148     fields['scope'] = fields['to_user']
   165     fields['from_user'] = current_user
   149     fields['from_user'] = current_user
   166     fields['scope_path'] = fields['to_user']
   150     fields['scope_path'] = fields['to_user'].link_id
   167 
   151 
   168   def _editSeed(self, request, seed):
   152   def _editSeed(self, request, seed):
   169     """Checks if scope_path is seeded and puts it into to_user.
   153     """Checks if scope_path is seeded and puts it into to_user.
   170 
   154 
   171     for parameters see base._editSeed()
   155     for parameters see base._editSeed()