Thanks arie, the answer helped a long way, but it did not work for me.
When I found this snippet, I got it to work correctly: http://djangosnippets.org/snippets/983/
This solution worked for me:
Helper function
This function has the advantage of being reused elsewhere, as a replacement when replacing user.is_authenticated . This can be, for example, shown as a template tag.
def my_custom_authenticated(user): if user: if user.is_authenticated(): return user.groups.filter(name=settings.MY_CUSTOM_GROUP_NAME).exists() return False
Decorator
I just put this on top of my views.py since it is so short.
def membership_required(fn=None): decorator = user_passes_test(my_custom_authenticated) if fn: return decorator(fn) return decorator
Using
@membership_required def some_view(request): ...
thnee Mar 29 '13 at 15:06 2013-03-29 15:06
source share