app/soc/views/models/user_self.py
changeset 710 edb5dbb1dea7
parent 696 0d8515fb5314
child 726 ba3d399ec9be
equal deleted inserted replaced
709:e71b20847eb0 710:edb5dbb1dea7
    95     """
    95     """
    96 
    96 
    97     rights = {}
    97     rights = {}
    98     rights['unspecified'] = [access.deny]
    98     rights['unspecified'] = [access.deny]
    99     rights['any_access'] = [access.allow]
    99     rights['any_access'] = [access.allow]
   100     rights['editSelf'] = [access.checkIsLoggedIn]
   100     rights['edit'] = [access.checkIsLoggedIn]
   101     rights['roles'] = [access.checkIsUser]
   101     rights['roles'] = [access.checkIsUser]
   102     rights['signIn'] = [access.checkNotLoggedIn]
   102     rights['signIn'] = [access.checkNotLoggedIn]
   103 
   103 
   104     new_params = {}
   104     new_params = {}
   105     new_params['rights'] = rights
   105     new_params['rights'] = rights
   112     new_params['module_name'] = "user_self"
   112     new_params['module_name'] = "user_self"
   113     
   113     
   114     new_params['sidebar_heading'] = 'User (self)'
   114     new_params['sidebar_heading'] = 'User (self)'
   115     new_params['sidebar'] = [
   115     new_params['sidebar'] = [
   116         (users.create_login_url("user/edit"), 'Sign In', 'signIn'),
   116         (users.create_login_url("user/edit"), 'Sign In', 'signIn'),
   117         ('/' + new_params['url_name'] + '/edit', 'Profile', 'editSelf'),
   117         ('/' + new_params['url_name'] + '/edit', 'Profile', 'edit'),
   118         ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
   118         ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
   119         ]
   119         ]
   120 
   120 
   121     patterns = []
   121     patterns = []
   122 
   122 
   123     page_name = "Profile"
   123     page_name = "Profile"
   124     patterns += [(r'^%(url_name)s/edit$',
   124     patterns += [(r'^%(url_name)s/(?P<access_type>edit)$',
   125                   'soc.views.models.%(module_name)s.edit', page_name)]
   125                   'soc.views.models.%(module_name)s.edit', page_name)]
   126 
   126 
   127     page_name = "Requests Overview"
   127     page_name = "Requests Overview"
   128     patterns += [(r'^%(url_name)s/roles$',
   128     patterns += [(r'^%(url_name)s/(?P<access_type>roles)$',
   129                    'soc.views.models.request.list_self', page_name)]
   129                    'soc.views.models.request.list_self', page_name)]
   130 
   130 
   131     new_params['django_patterns_defaults'] = patterns
   131     new_params['django_patterns_defaults'] = patterns
   132 
   132 
   133     params = dicts.merge(params, new_params)
   133     params = dicts.merge(params, new_params)
   134 
   134 
   135     super(View, self).__init__(params=params)
   135     super(View, self).__init__(params=params)
   136 
   136 
   137   EDIT_SELF_TMPL = 'soc/user/edit_self.html'
   137   EDIT_SELF_TMPL = 'soc/user/edit_self.html'
   138 
   138 
   139   def edit(self, request, page_name=None, params=None, seed=None, **kwargs):
   139   def edit(self, request, access_type,
       
   140            page_name=None, params=None, seed=None, **kwargs):
   140     """Displays User self edit page for the entity specified by **kwargs.
   141     """Displays User self edit page for the entity specified by **kwargs.
   141 
   142 
   142     Args:
   143     Args:
   143       request: the standard Django HTTP request object
   144       request: the standard Django HTTP request object
   144       page_name: the page name displayed in templates as page and header title
   145       page_name: the page name displayed in templates as page and header title
   151 
   152 
   152     params = dicts.merge(params, new_params)
   153     params = dicts.merge(params, new_params)
   153     params = dicts.merge(params, self._params)
   154     params = dicts.merge(params, self._params)
   154 
   155 
   155     try:
   156     try:
   156       access.checkAccess('editSelf', request, params['rights'])
   157       access.checkAccess(access_type, request, params['rights'])
   157     except out_of_band.Error, error:
   158     except out_of_band.Error, error:
   158       return helper.responses.errorResponse(error, request, 
   159       return helper.responses.errorResponse(error, request, 
   159           template=self.EDIT_SELF_TMPL)
   160           template=self.EDIT_SELF_TMPL)
   160 
   161 
   161     account = users.get_current_user()
   162     account = users.get_current_user()