app/soc/views/models/user_self.py
changeset 826 c8dbcfd38c03
parent 825 0ac8c43efd52
child 837 bc1c951bf3a0
equal deleted inserted replaced
825:0ac8c43efd52 826:c8dbcfd38c03
    25 
    25 
    26 from google.appengine.api import users
    26 from google.appengine.api import users
    27 
    27 
    28 from django import forms
    28 from django import forms
    29 from django import http
    29 from django import http
       
    30 from django.utils.encoding import force_unicode
       
    31 from django.utils.safestring import mark_safe
    30 from django.utils.translation import ugettext_lazy
    32 from django.utils.translation import ugettext_lazy
    31 
    33 
    32 from soc.logic import dicts
    34 from soc.logic import dicts
    33 from soc.logic import validate
    35 from soc.logic import validate
       
    36 from soc.logic import models as model_logic
    34 from soc.logic.models import user as user_logic
    37 from soc.logic.models import user as user_logic
    35 from soc.views import helper
    38 from soc.views import helper
    36 from soc.views import out_of_band
    39 from soc.views import out_of_band
    37 from soc.views.helper import access
    40 from soc.views.helper import access
    38 from soc.views.models import base
    41 from soc.views.models import base
   113     new_params['sidebar_heading'] = 'User (self)'
   116     new_params['sidebar_heading'] = 'User (self)'
   114     new_params['sidebar'] = [
   117     new_params['sidebar'] = [
   115         (users.create_login_url("/user/edit"), 'Sign In', 'signIn'),
   118         (users.create_login_url("/user/edit"), 'Sign In', 'signIn'),
   116         ('/' + new_params['url_name'] + '/edit', 'Profile', 'edit'),
   119         ('/' + new_params['url_name'] + '/edit', 'Profile', 'edit'),
   117         ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
   120         ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
   118         ('/' + 'notification/list', 'Notifications', 'notification'),
       
   119         ]
   121         ]
   120 
   122 
   121     patterns = []
   123     patterns = []
   122 
   124 
   123     page_name = "Profile"
   125     page_name = "Profile"
   242     # fill in the account field with the user created from email
   244     # fill in the account field with the user created from email
   243     fields['account'] = users.User(fields['email'])
   245     fields['account'] = users.User(fields['email'])
   244 
   246 
   245     super(View, self)._editPost(request, entity, fields)
   247     super(View, self)._editPost(request, entity, fields)
   246 
   248 
       
   249   def getSidebarMenus(self, request, params=None):
       
   250     """See base.View.getSidebarMenus()
       
   251     """
       
   252 
       
   253     link_title = ugettext_lazy('Notifications')
       
   254 
       
   255     user = user_logic.logic.getForCurrentAccount()
       
   256 
       
   257     filter = {
       
   258         'scope': user,
       
   259         'unread': True,
       
   260         }
       
   261 
       
   262     notifications = model_logic.notification.logic.getForFields(filter)
       
   263     count = len(list(notifications))
       
   264 
       
   265     if count > 0:
       
   266       link_title = '<b>%s (%d)</b>' % (force_unicode(link_title), count)
       
   267       link_title = mark_safe(link_title)
       
   268 
       
   269     items = [('/' + 'notification/list', link_title, 'notification')]
       
   270 
       
   271     new_params = {}
       
   272     new_params['sidebar'] = items
       
   273 
       
   274     params = dicts.merge(params, new_params)
       
   275 
       
   276     return super(View, self).getSidebarMenus(request, params=params)
       
   277 
   247 
   278 
   248 view = View()
   279 view = View()
   249 
   280 
   250 edit = view.edit
   281 edit = view.edit