3
from views import publisher
6
def forbidden(request, error_message=None):
7
"""Returns a 403 response based on a template.
10
request: the http request that was forbidden
11
error_message: a message to display that will override the default message
14
A http response with the status code of 403
17
response = publisher.respond(request, '403', {'error_message': error_message})
18
response.status_code = 403
22
def admin_required(func):
23
"""Ensure that the logged in user is an administrator."""
25
@functools.wraps(func)
26
def __wrapper(request, *args, **kwds):
27
"""Makes it possible for admin_required to be used as a decorator."""
28
if request.user_is_admin:
29
return func(request, *args, **kwds) # pylint: disable-msg=W0142
33
error_message='You must be an administrator to view this page.')
38
def super_user_required(func):
39
"""Ensure that the logged in user has editing privileges."""
41
@functools.wraps(func)
42
def __wrapper(request, *args, **kwds):
43
"""Makes it possible for super_user_required to be used as a decorator."""
44
if request.profile.is_superuser:
45
return func(request, *args, **kwds) # pylint: disable-msg=W0142
49
error_message='You must be a superuser to view this page.')