app/soc/views/models/notification.py
changeset 827 88c186556a80
parent 799 30a912906a57
child 829 595b34a71cbb
equal deleted inserted replaced
826:c8dbcfd38c03 827:88c186556a80
    31 from soc.logic import dicts
    31 from soc.logic import dicts
    32 from soc.logic import validate
    32 from soc.logic import validate
    33 from soc.models import notification as notification_model
    33 from soc.models import notification as notification_model
    34 from soc.views import helper
    34 from soc.views import helper
    35 from soc.views.helper import access
    35 from soc.views.helper import access
       
    36 from soc.views.helper import lists as list_helper
    36 from soc.views.helper import redirects
    37 from soc.views.helper import redirects
    37 from soc.views.models import base
    38 from soc.views.models import base
    38 from soc.logic.models import notification as notification_logic
    39 from soc.logic.models import notification as notification_logic
    39 from soc.logic.models import user as user_logic
    40 from soc.logic.models import user as user_logic
    40 
    41 
   110     for parameters see base.list()
   111     for parameters see base.list()
   111     """
   112     """
   112 
   113 
   113     params = dicts.merge(params, self._params)
   114     params = dicts.merge(params, self._params)
   114 
   115 
       
   116     try:
       
   117       access.checkAccess(access_type, request, params['rights'])
       
   118     except out_of_band.Error, error:
       
   119       return helper.responses.errorResponse(error, request)
       
   120 
   115     # get the current user
   121     # get the current user
   116     user_entity = user_logic.logic.getForCurrentAccount()
   122     user_entity = user_logic.logic.getForCurrentAccount()
   117 
   123 
   118     # only select the notifications for this user so construct a filter
   124     # only select the notifications for this user so construct a filter
   119     filter = {'scope': user_entity}
   125     filter = {
       
   126         'scope': user_entity,
       
   127         'unread': True,
       
   128         }
   120 
   129 
   121     # create the list parameters
   130     # create the list parameters
   122     list_params = params.copy()
   131     un_params = params.copy() # unread notifications
   123 
   132 
   124     # define the list redirect action to show the notification
   133     # define the list redirect action to show the notification
   125     list_params['list_action'] = (redirects.getPublicRedirect, params)
   134     un_params['list_action'] = (redirects.getPublicRedirect, params)
   126     list_params['list_description'] = ugettext_lazy(
   135     un_params['list_description'] = ugettext_lazy(
   127         "An overview of your received Notifications.")
   136         "An overview of your unread Notifications.")
   128 
   137 
   129     # TODO(Lennard) when list sorting is implemented sort on descending date
   138     # TODO(Lennard) when list sorting is implemented sort on descending date
   130 
   139     un_list = list_helper.getListContent(
   131     # use the generic list method with the filter. The access check in this
   140         request, un_params, filter, 0)
   132     # method will trigger an errorResponse when user_entity is None
   141 
   133     return super(View, self).list(request, access_type,
   142     # Now get the read list
   134         page_name, list_params, filter)
   143 
       
   144     # Reuse the filter, but only for read notifications
       
   145     filter['unread'] = False
       
   146 
       
   147     rn_params = params.copy() # read notifications
       
   148 
       
   149     rn_params['list_action'] = (redirects.getPublicRedirect, params)
       
   150     rn_params['list_description'] = ugettext_lazy(
       
   151         "An overview of your read Notifications.")
       
   152 
       
   153     rn_list = list_helper.getListContent(
       
   154         request, rn_params, filter, 1)
       
   155 
       
   156     # fill contents with all the needed lists
       
   157     contents = [un_list, rn_list]
       
   158 
       
   159     # call the _list method from base to display the list
       
   160     return self._list(request, params, contents, page_name)
   135 
   161 
   136   def _editPost(self, request, entity, fields):
   162   def _editPost(self, request, entity, fields):
   137     """See base.View._editPost().
   163     """See base.View._editPost().
   138     """
   164     """
   139 
   165