app/soc/views/models/user_self.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 20 Mar 2009 14:18:07 +0000
changeset 1951 921069bcc6e1
parent 1950 27c0ea479d8a
child 1986 5375e657a715
permissions -rw-r--r--
Fixed copy/paste fail in docstring. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
590
37735d97b541 Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents: 587
diff changeset
    17
"""Views for the User's own profiles.
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
470
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
    23
    '"Pawel Solyga" <pawel.solyga@gmail.com>',
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
  ]
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    26
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
    27
import datetime
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
    28
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from google.appengine.api import users
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
    31
from django import forms
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
    32
from django.utils.encoding import force_unicode
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
    33
from django.utils.safestring import mark_safe
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 890
diff changeset
    34
from django.utils.translation import ugettext
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    36
from soc.logic import cleaning
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
from soc.logic import dicts
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
    38
from soc.logic import models as model_logic
860
cfb57fe35d3c Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents: 858
diff changeset
    39
from soc.logic.models.user import logic as user_logic
1460
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    40
from soc.logic.models.site import logic as site_logic
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
from soc.views import helper
515
fa235f6759f3 Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 514
diff changeset
    42
from soc.views.helper import access
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 860
diff changeset
    43
from soc.views.helper import decorators
1120
2b5c976e7edd Add an 'unread' style and add 'new document' link for user
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1079
diff changeset
    44
from soc.views.helper import redirects
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    45
from soc.views.helper import widgets
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
from soc.views.models import base
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
    47
from soc.views.models import role as role_view
515
fa235f6759f3 Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 514
diff changeset
    48
fa235f6759f3 Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 514
diff changeset
    49
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
class View(base.View):
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    51
  """Views for User own profiles.
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
1401
6d9f134ac531 Wording nitpick fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1384
diff changeset
    54
  DEF_ROLE_LIST_MSG_FMT = ugettext("Your roles as %(name)s.")
1460
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    55
  DEF_NO_ROLES_MSG_FMT = ugettext("You don't have any Roles in %s.")
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
    56
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    57
  def __init__(self, params=None):
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
    """Defines the fields and methods required for the base View class
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
    to provide the user with list, public, create, edit and delete views.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    62
      params: a dict with params for this View
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    65
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    66
    rights['unspecified'] = ['deny']
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    67
    rights['any_access'] = ['allow']
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    68
    rights['create_profile'] = ['checkIsUnusedAccount']
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    69
    rights['edit_profile'] = ['checkHasUserEntity']
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    70
    rights['roles'] = ['checkIsUser']
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
    71
    rights['requests'] = ['checkIsUser']
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 973
diff changeset
    72
    rights['signIn'] = ['checkNotLoggedIn']
1012
73f0b61f2d9d Fold checkAgreesToSiteToS into checkIsUser
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1007
diff changeset
    73
    rights['notification'] = ['checkIsUser']
587
7504504209a3 Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents: 586
diff changeset
    74
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    75
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    76
    new_params['rights'] = rights
860
cfb57fe35d3c Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents: 858
diff changeset
    77
    new_params['logic'] = user_logic
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    79
    new_params['name'] = "User"
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 787
diff changeset
    80
    new_params['module_name'] = "user_self"
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
    81
    new_params['url_name'] = "user"
799
30a912906a57 Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 787
diff changeset
    82
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    83
    new_params['create_template'] = 'soc/user/edit_profile.html'
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    84
    new_params['edit_template'] = 'soc/user/edit_profile.html'
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    85
    new_params['save_message'] = [ugettext('Profile saved.')]
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    86
    new_params['edit_redirect'] = '/%(url_name)s/edit_profile'
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    87
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    88
    # set the specific fields for the users profile page
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    89
    new_params['extra_dynaexclude'] = ['former_accounts', 
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
    90
        'account', 'is_developer', 'status', 'agreed_to_tos_on']
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
    91
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1401
diff changeset
    92
    new_params['create_extra_dynaproperties'] = {
1144
f89bbc9b20a6 Rename 'Create a new document' links to 'Create a New Document', also rename 'Create a new Program' to 'Create a New Program' in soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1120
diff changeset
    93
        'clean_agreed_to_tos': cleaning.clean_agrees_to_tos('agreed_to_tos'),
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    94
        'clean_link_id': cleaning.clean_user_not_exist('link_id'),}
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
    95
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1401
diff changeset
    96
    new_params['edit_extra_dynaproperties'] = {
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
    97
        'clean_link_id': cleaning.clean_link_id('link_id'),
1168
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
    98
        'agreed_to_tos_on': forms.DateTimeField(
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
    99
          widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   100
          required=False),
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   101
        }
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 860
diff changeset
   102
696
0d8515fb5314 Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   103
    new_params['sidebar_heading'] = 'User (self)'
0d8515fb5314 Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   104
    new_params['sidebar'] = [
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   105
        (users.create_login_url("/"), 'Sign In', 'signIn'),
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   106
        ('/' + new_params['url_name'] + '/create_profile', 
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   107
            'Create Profile', 'create_profile'),
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   108
        ('/' + new_params['url_name'] + '/edit_profile', 
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   109
            'Edit Profile', 'edit_profile'),
696
0d8515fb5314 Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   110
        ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   111
        ('/' + new_params['url_name'] + '/requests', 'Requests', 'requests'),
696
0d8515fb5314 Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   112
        ]
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 531
diff changeset
   113
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   114
    patterns = []
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   115
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   116
    page_name = ugettext("Create your profile")
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   117
    patterns += [(r'^%(url_name)s/(?P<access_type>create_profile)$',
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   118
                  'soc.views.models.%(module_name)s.create', page_name)]
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   119
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   120
    page_name = ugettext("Edit your profile")
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   121
    patterns += [(r'^%(url_name)s/(?P<access_type>edit_profile)$',
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   122
                  'soc.views.models.%(module_name)s.edit', page_name)]
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   123
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   124
    page_name = ugettext("List of your roles")
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 696
diff changeset
   125
    patterns += [(r'^%(url_name)s/(?P<access_type>roles)$',
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   126
                   'soc.views.models.user_self.roles', page_name)]
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   127
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   128
    page_name = ugettext("List of your requests")
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   129
    patterns += [(r'^%(url_name)s/(?P<access_type>requests)$',
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   130
                   'soc.views.models.request.list_self', page_name)]
1181
6fb4134e1dfc Calling getForCurrentAccount where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1169
diff changeset
   131
660
5a381b290691 Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   132
    new_params['django_patterns_defaults'] = patterns
1181
6fb4134e1dfc Calling getForCurrentAccount where necessary.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1169
diff changeset
   133
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   134
    params = dicts.merge(params, new_params)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   136
    super(View, self).__init__(params=params)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
876
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 860
diff changeset
   138
  @decorators.merge_params
0c1329d4b514 Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 860
diff changeset
   139
  @decorators.check_access
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   140
  def editProfile(self, request, access_type,
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 696
diff changeset
   141
           page_name=None, params=None, seed=None, **kwargs):
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   142
    """Displays User profile edit page for the current user.
470
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   143
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   144
    Args:
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   145
      request: the standard Django HTTP request object
500
44ea4620c5c0 Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   146
      page_name: the page name displayed in templates as page and header title
470
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   147
      params: a dict with params for this View
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   148
      kwargs: The Key Fields for the specified entity
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   151
    # set the link_id to the current user's link_id
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   152
    user_entity = user_logic.getForCurrentAccount()
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   153
    link_id = user_entity.link_id
515
fa235f6759f3 Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 514
diff changeset
   154
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   155
    return self.edit(request, access_type, page_name=page_name, 
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   156
        params=params, seed=seed, link_id=link_id, **kwargs)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   158
  def editGet(self, request, entity, context, seed, params=None):
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   159
    """Overwrite so we can add the contents of the ToS.
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   160
    For params see base.View.editGet().
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   161
    """
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   162
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   163
    s_logic = model_logic.site.logic
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   164
    site_tos = s_logic.getToS(s_logic.getSingleton())
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   165
    if site_tos:
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   166
      context['tos_contents'] = site_tos.content
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   167
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   168
    return super(View, self).editGet(request, entity, context, 
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   169
        seed, params=params)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   170
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   171
  def _editGet(self, request, entity, form):
1168
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   172
    """Sets the content of the agreed_to_tos_on field and replaces.
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   173
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   174
    Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed.
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   175
    For params see base.View._editGet().
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   176
    """
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   177
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   178
    if entity.agreed_to_tos:
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   179
      form.fields['agreed_to_tos_on'].initial = entity.agreed_to_tos_on
1168
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   180
      # replace the 'agreed_to_tos' field with a hidden field so 
cb282e6baa1c Adding a hidden agreed_to_tos field when the user has signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1164
diff changeset
   181
      # that the form checks still pass
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   182
      form.fields['agreed_to_tos'] = forms.fields.BooleanField(
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   183
          widget=forms.HiddenInput, initial=entity.agreed_to_tos, required=True)
1164
d0e14654431a User profile now shows the time on which you signed the ToS.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1157
diff changeset
   184
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   185
  def editPost(self, request, entity, context, params=None):
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   186
    """Overwrite so we can add the contents of the ToS.
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   187
    For params see base.View.editPost().
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   188
    """
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   189
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   190
    s_logic = model_logic.site.logic
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   191
    site_tos = s_logic.getToS(s_logic.getSingleton())
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   192
    if site_tos:
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   193
      context['tos_contents'] = site_tos.content
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   194
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   195
    return super(View, self).editPost(request, entity, context, params=params)
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   196
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   197
  def _editPost(self, request, entity, fields):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   198
    """See base.View._editPost().
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   199
    """
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   200
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   201
    # fill in the account field with the current User
1047
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   202
    fields['account'] = users.User()
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   203
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   204
    # special actions if there is no ToS present
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   205
    s_logic = model_logic.site.logic
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   206
    site_tos = s_logic.getToS(s_logic.getSingleton())
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   207
    if not site_tos:
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   208
      # there is no Terms of Service set
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   209
      if not entity:
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   210
        # we are a new user so set the agrees_to_tos field to None
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   211
        fields['agreed_to_tos'] = None
1047
26fade94886b Changed the Terms Of Service boolean so that it is None as long as the user owning the account has not Agreed to it.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1043
diff changeset
   212
      else:
1076
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   213
        # editing an existing user so no value changes allowed
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   214
        fields['agreed_to_tos'] = entity.agreed_to_tos
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   215
    else:
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   216
      if not entity or not entity.agreed_to_tos:
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   217
        # set the time of agreement
063194eaf87b Added agreed_to_tos_on field in user and role model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1047
diff changeset
   218
        fields['agreed_to_tos_on'] = datetime.datetime.now()
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   219
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   220
    super(View, self)._editPost(request, entity, fields)
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 660
diff changeset
   221
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   222
  @decorators.merge_params
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   223
  @decorators.check_access
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   224
  def roles(self, request, access_type,
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   225
               page_name=None, params=None, **kwargs):
1951
921069bcc6e1 Fixed copy/paste fail in docstring.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1950
diff changeset
   226
    """Displays the valid roles for this user.
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   227
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   228
    Args:
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   229
      request: the standard Django HTTP request object
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   230
      access_type : the name of the access type which should be checked
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   231
      page_name: the page name displayed in templates as page and header title
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   232
      params: a dict with params for this View
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   233
      kwargs: not used
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   234
    """
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   235
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   236
    user = user_logic.getForCurrentAccount()
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   237
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   238
    # only select the roles for the current user
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   239
    filter = {
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   240
        'link_id': user.link_id,
1950
27c0ea479d8a Only show valid roles on user roles page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1667
diff changeset
   241
        'status': ['active', 'inactive']
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   242
        }
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   243
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   244
    contents = []
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   245
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   246
    i = 0
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   247
1647
8bbe06730867 Rename unused loop variable to _ in soc.views.models.user_self module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1634
diff changeset
   248
    for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()):
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   249
      list_params = loop_view.getParams().copy()
1464
a7b00937b678 Fixed params used for list_action and list_description in user_self roles overview.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1460
diff changeset
   250
      list_params['list_action'] = (redirects.getEditRedirect, list_params)
a7b00937b678 Fixed params used for list_action and list_description in user_self roles overview.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1460
diff changeset
   251
      list_params['list_description'] = self.DEF_ROLE_LIST_MSG_FMT % list_params
1460
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   252
1667
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1647
diff changeset
   253
      list = helper.lists.getListContent(request, list_params, filter,
95bc81b4cd5c Updated list to use the new order in getForFields.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1647
diff changeset
   254
                                         idx=i, need_content=True)
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   255
1460
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   256
      if list:
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   257
        contents.append(list)
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   258
        i += 1
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   259
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   260
    site = site_logic.getSingleton()
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   261
    site_name = site.site_name
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   262
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   263
    params = params.copy()
8f3acefaa4e3 Don't show empty lists in /user/roles
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   264
    params['no_lists_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name
1347
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   265
88dac688b673 Rename current 'roles' view to 'request' and add a real roles view
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1317
diff changeset
   266
    return self._list(request, params, contents, page_name)
1043
5e15994b2033 Redone the user's profile page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1017
diff changeset
   267
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
   268
  def getSidebarMenus(self, id, user, params=None):
837
bc1c951bf3a0 Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 826
diff changeset
   269
    """See base.View.getSidebarMenus().
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   270
    """
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   271
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 890
diff changeset
   272
    link_title = ugettext('Notifications')
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   273
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   274
    filter = {
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   275
        'scope': user,
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   276
        'unread': True,
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   277
        }
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   278
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   279
    notifications = model_logic.notification.logic.getForFields(filter)
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   280
    count = len(list(notifications))
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   281
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   282
    if count > 0:
1634
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   283
      link_title = '<span class="unread">%s (%d)</span>' % (
85bbf50038b8 Remove unused imports and fix too long lines in soc.views.models.user_self module
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1584
diff changeset
   284
          force_unicode(link_title), count)
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   285
      link_title = mark_safe(link_title)
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   286
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   287
    items = [('/' + 'notification/list', link_title, 'notification')]
1120
2b5c976e7edd Add an 'unread' style and add 'new document' link for user
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1079
diff changeset
   288
    if user:
2b5c976e7edd Add an 'unread' style and add 'new document' link for user
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1079
diff changeset
   289
      items += [(redirects.getCreateDocumentRedirect(user, 'user'),
2b5c976e7edd Add an 'unread' style and add 'new document' link for user
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1079
diff changeset
   290
          "Create a New Document", 'any_access')]
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   291
1317
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   292
      items += [(redirects.getListDocumentsRedirect(user, 'user'),
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   293
          "List Documents", 'any_access')]
fad74cf4e5da Add a 'list documents' link everywhere
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   294
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   295
    new_params = {}
840
d3f9fff0860b When constructing the sidebar don't overide 'sidebar'
Sverre Rabbelier <srabbelier@gmail.com>
parents: 837
diff changeset
   296
    new_params['sidebar_additional'] = items
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   297
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   298
    params = dicts.merge(params, new_params)
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   299
1017
6ad4fdb48840 Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1012
diff changeset
   300
    return super(View, self).getSidebarMenus(id, user, params=params)
826
c8dbcfd38c03 Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents: 825
diff changeset
   301
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   302
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   303
view = View()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   304
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1464
diff changeset
   305
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1464
diff changeset
   306
edit = decorators.view(view.editProfile)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1464
diff changeset
   307
export = decorators.view(view.export)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1464
diff changeset
   308
roles = decorators.view(view.roles)