Created
April 5, 2015 00:13
-
-
Save MarkusH/f55fca3a003723efb2a3 to your computer and use it in GitHub Desktop.
Require a user to be a member of a specific group to visit a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def require_group(group_name): | |
def wrapper(user): | |
return user.groups.filter(name=group_name).exists() | |
return wrapper | |
@user_passes_test(require_group('Group 1')) | |
def view1(request): | |
# ... | |
@user_passes_test(require_group('Group 2')) | |
def view2(request): | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment