I'm creating a decorator for Django views that will check permissions in a non-Django-managed database. Here is the decorator:
def check_ownership(failure_redirect_url='/', *args, **kwargs):
def _check_ownership(view):
def _wrapper(request, csi=None):
try:
opb_id=request.user.get_profile().opb_id
if opb_id and csi and model.is_users_server(opb_id, csi):
return view(*args, **kwargs)
except Exception, e:
logger.debug("Exception checking ownership: %s", str(e))
return HttpResponseRedirect(failure_redirect_url)
_wrapper.__dict__=view.__dict__
_wrapper.__doc__=view.__doc__
return _wrapper
return _check_ownership
And this is how it is being used:
@check_ownership
def my_view(request, csi=None):
"""Process my request"""
check_ownership() is being called and returning _check_ownership(). When _check_ownership() is called, it is being called with a WSGIRequest object which is what I would have expected _wrapper() to be called with. Anybody have any idea where my method has gone and how I can get it back? I don't have a way to chain to the next decorator or the actual view the way things stand.
Oh, Python 2.4.3 on CentOS and Django 1.1.1.
I want my function back! ;)
Thanks.
tj