Make use of the new decorators in all applicable views
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/base.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/base.py Wed Jan 21 16:12:48 2009 +0000
@@ -30,7 +30,7 @@
from soc.logic import dicts
from soc.views import helper
from soc.views import out_of_band
-from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.helper import forms
from soc.views.helper import redirects
from soc.views import sitemap
@@ -71,7 +71,8 @@
self._params = helper.params.constructParams(params)
self._logic = params['logic']
-
+ @decorators.merge_params
+ @decorators.check_access
def public(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Displays the public page for the entity specified by **kwargs.
@@ -96,13 +97,6 @@
kwargs: the Key Fields for the specified entity
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
context['page_name'] = page_name
@@ -128,6 +122,8 @@
return helper.responses.respond(request, template, context=context)
+ @decorators.merge_params
+ @decorators.check_access
def export(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Displays the export page for the entity specified by **kwargs.
@@ -154,17 +150,11 @@
params: a dict with params for this View
kwargs: the Key Fields for the specified entity
"""
- params = dicts.merge(params, self._params)
if not params.get('export_content_type'):
return self.public(request, access_type, page_name=page_name,
params=params, **kwargs)
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
context['page_name'] = page_name
@@ -193,6 +183,7 @@
return helper.responses.respond(request, template, context=context,
response_args=response_args)
+ @decorators.check_access
def create(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Displays the create page for this entity type.
@@ -227,6 +218,8 @@
return self.edit(request, access_type, page_name=page_name,
params=params, seed=kwargs, **empty_kwargs)
+ @decorators.merge_params
+ @decorators.check_access
def edit(self, request, access_type,
page_name=None, params=None, seed=None, **kwargs):
"""Displays the edit page for the entity specified by **kwargs.
@@ -256,13 +249,6 @@
kwargs: The Key Fields for the specified entity
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
context = helper.responses.getUniversalContext(request)
context['page_name'] = page_name
entity = None
@@ -282,11 +268,12 @@
error, request, template=params['error_public'], context=context)
if request.method == 'POST':
- return self.editPost(request, entity, context, params)
+ return self.editPost(request, entity, context, params=params)
else:
- return self.editGet(request, entity, context, seed, params)
+ return self.editGet(request, entity, context, seed, params=params)
- def editPost(self, request, entity, context, params):
+ @decorators.merge_params
+ def editPost(self, request, entity, context, params=None):
"""Processes POST requests for the specified entity.
Params usage:
@@ -312,11 +299,9 @@
request: a django request object
entity: the entity that will be modified or created, may be None
context: the context dictionary that will be provided to Django
- params: a dict with params for this View
+ params: required, a dict with params for this View
"""
- params = dicts.merge(params, self._params)
-
if entity:
form = params['edit_form'](request.POST)
else:
@@ -348,7 +333,8 @@
return helper.responses.redirectToChangedSuffix(
request, None, params=page_params)
- def editGet(self, request, entity, context, seed, params):
+ @decorators.merge_params
+ def editGet(self, request, entity, context, seed, params=None):
"""Processes GET requests for the specified entity.
Params usage:
@@ -376,10 +362,9 @@
entity: the entity that will be edited, may be None
context: the context dictionary that will be provided to django
seed: if no entity is provided, the initial values for the new entity
- params: a dict with paras for this View
+ params: required, a dict with params for this View
"""
- params = dicts.merge(params, self._params)
suffix = self._logic.getKeySuffix(entity)
# Remove the params from the request, this is relevant only if
@@ -411,6 +396,8 @@
return self._constructResponse(request, entity, context, form, params)
+ @decorators.merge_params
+ @decorators.check_access
def list(self, request, access_type,
page_name=None, params=None, filter=None):
"""Displays the list page for the entity type.
@@ -426,20 +413,8 @@
the soc.views.helper.list module. See the docstring for getListContent
on how it uses it. The params dictionary is also passed as argument to
the _list method. See the docstring for _list on how it uses it.
-
- rights: The rights dictionary is used to check if the user has
- the required rights to list all entities of this View's type.
- See checkAccess for more details on how the rights dictionary
- is used to check access rights.
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
content = helper.lists.getListContent(request, params, filter)
contents = [content]
@@ -475,6 +450,8 @@
return helper.responses.respond(request, template, context)
+ @decorators.merge_params
+ @decorators.check_access
def delete(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Shows the delete page for the entity specified by **kwargs.
@@ -498,13 +475,6 @@
redirect to after having successfully deleted the entity.
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
context['page_name'] = page_name
@@ -539,8 +509,8 @@
def select(self, request, view, redirect, page_name=None, params=None):
"""Displays a list page allowing the user to select an entity.
- After having selected the Sponsor, the user is redirected to the
- 'create a new program' page with the scope_path set appropriately.
+ After having selected the Scope, the user is redirected to the
+ 'create a new entity' page with the scope_path set appropriately.
Params usage:
The params dictionary is also passed to getListContent from
@@ -678,6 +648,7 @@
return self._params
+ @decorators.merge_params
def getSidebarMenus(self, request, params=None):
"""Returns an dictionary with one sidebar entry.
@@ -691,9 +662,9 @@
of _getSidebarItems on how it uses it.
"""
- params = dicts.merge(params, self._params)
return sitemap.sidebar.getSidebarMenus(request, params)
+ @decorators.merge_params
def getDjangoURLPatterns(self, params=None):
"""Retrieves a list of sidebar entries for this view
@@ -706,6 +677,5 @@
params: a dict with params for this View
"""
- params = dicts.merge(params, self._params)
return sitemap.sitemap.getDjangoURLPatterns(params)
--- a/app/soc/views/models/club_app.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/club_app.py Wed Jan 21 16:12:48 2009 +0000
@@ -35,6 +35,7 @@
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.helper import redirects
from soc.views.helper import lists as list_helper
from soc.views.models import group_app
@@ -102,6 +103,8 @@
super(View, self).__init__(params=params)
+ @decorators.merge_params
+ @decorators.check_access
def list(self, request, access_type,
page_name=None, params=None, filter=None):
"""Lists all notifications that the current logged in user has stored.
@@ -109,13 +112,6 @@
for parameters see base.list()
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# get the current user
user_entity = user_logic.logic.getForCurrentAccount()
@@ -214,6 +210,8 @@
context['entity_type_url'] = self._params['url_name']
+ @decorators.merge_params
+ @decorators.check_access
def review(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Handles the view containing the review of an application.
@@ -225,13 +223,6 @@
For params see base.View.public().
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, rights=params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
context['page_name'] = page_name
@@ -278,6 +269,8 @@
return super(View, self).public(request, access_type,
page_name=page_name, params=params, **kwargs)
+ @decorators.merge_params
+ @decorators.check_access
def reviewOverview(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Displays multiple lists of applications that are in different
--- a/app/soc/views/models/notification.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/notification.py Wed Jan 21 16:12:48 2009 +0000
@@ -34,6 +34,7 @@
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.helper import lists as list_helper
from soc.views.helper import redirects
from soc.views.models import base
@@ -105,6 +106,8 @@
super(View, self).__init__(params=params)
+ @decorators.merge_params
+ @decorators.check_access
def list(self, request, access_type,
page_name=None, params=None, filter=None):
"""Lists all notifications that the current logged in user has stored.
@@ -112,13 +115,6 @@
for parameters see base.list()
"""
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# get the current user
user_entity = user_logic.logic.getForCurrentAccount()
--- a/app/soc/views/models/request.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/request.py Wed Jan 21 16:12:48 2009 +0000
@@ -35,6 +35,7 @@
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.helper import redirects
from soc.views.models import base
@@ -122,7 +123,8 @@
super(View, self).__init__(params=params)
-
+ @decorators.merge_params
+ @decorators.check_access
def listSelf(self, request, access_type,
page_name=None, params=None, **kwargs):
"""Displays the unhandled requests for this user.
@@ -134,14 +136,6 @@
kwargs: not used
"""
- params = dicts.merge(params, self._params)
- params['logic'] = self._logic
-
- try:
- access.checkAccess(access_type, request, params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request)
-
# get the current user
properties = {'account': users.get_current_user()}
user_entity = user_logic.logic.getForFields(properties, unique=True)
--- a/app/soc/views/models/role.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/role.py Wed Jan 21 16:12:48 2009 +0000
@@ -30,6 +30,7 @@
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.helper import redirects
from soc.views.models import base
from soc.views.models import user as user_view
@@ -93,7 +94,7 @@
super(View, self).__init__(params=params)
def invite(self, request, access_type,
- page_name=None, params=None, **kwargs):
+ page_name=None, params=None, *args, **kwargs):
"""Displays the request promotion to Role page.
"""
@@ -110,9 +111,10 @@
new_params = dicts.merge(params, new_params)
params = dicts.merge(new_params, user_view.view._params)
+ rights = params['rights']
try:
- access.checkAccess(access_type, request, rights=params['rights'])
+ access.checkAccess(access_type, request, rights, args, kwargs)
except out_of_band.Error, error:
return helper.responses.errorResponse(error, request)
--- a/app/soc/views/models/user_self.py Wed Jan 21 16:12:31 2009 +0000
+++ b/app/soc/views/models/user_self.py Wed Jan 21 16:12:48 2009 +0000
@@ -39,6 +39,7 @@
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
+from soc.views.helper import decorators
from soc.views.models import base
import soc.models.linkable
@@ -127,6 +128,8 @@
new_params['module_name'] = "user_self"
new_params['url_name'] = "user"
+ new_params['edit_template'] = 'soc/user/edit_self.html'
+
new_params['sidebar_heading'] = 'User (self)'
new_params['sidebar'] = [
(users.create_login_url("/user/edit"), 'Sign In', 'signIn'),
@@ -150,8 +153,8 @@
super(View, self).__init__(params=params)
- EDIT_SELF_TMPL = 'soc/user/edit_self.html'
-
+ @decorators.merge_params
+ @decorators.check_access
def edit(self, request, access_type,
page_name=None, params=None, seed=None, **kwargs):
"""Displays User self edit page for the entity specified by **kwargs.
@@ -163,18 +166,6 @@
kwargs: The Key Fields for the specified entity
"""
- new_params = {}
- new_params['edit_template'] = self.EDIT_SELF_TMPL
-
- params = dicts.merge(params, new_params)
- params = dicts.merge(params, self._params)
-
- try:
- access.checkAccess(access_type, request, params['rights'])
- except out_of_band.Error, error:
- return helper.responses.errorResponse(error, request,
- template=self.EDIT_SELF_TMPL)
-
account = users.get_current_user()
properties = {'account': account}
@@ -202,7 +193,7 @@
'email': account.email()}
error = out_of_band.Error(msg)
return helper.responses.errorResponse(
- error, request, template=self.EDIT_SELF_TMPL, context=context)
+ error, request, template=params['edit_template'], context=context)
user = user_logic.updateOrCreateFromFields(
properties, {'link_id': new_link_id})