I would think the simplest thing to do is combine the get_object_or_404
and the user_can_access_c calls:
def get_allowed_c(request, cid):
c = get_object_or_404(C, pk=cid)
if user_can_access_c(request.user, c):
return c
else:
# not allowed; act as if user got the wrong
> What I currently have to do is to define each view (such as to handle
> "foo" above) as:
>
> @login_required
> def foo(request, cid):
> c = get_object_or_404(C, pk=cid)
> if user_can_access_c(request.user, c):
> # do something that's allowed
> # ...
> else:
>
I have a unique situation that the traditional urls.py config does not
handle very well.
Imagine I have URL patterns like this:
/c/(?P\d+)/foo
/c/(?P\d+)/bar
/c/(?P\d+)/abc
...
I'm using Django authentication to ensure the user is logged in. But I
have to do a custom check to ensure if that each
3 matches
Mail list logo