Created
November 3, 2014 18:38
-
-
Save lightstrike/9cda4cba2b2efb6862d4 to your computer and use it in GitHub Desktop.
User View Mixins
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
class UserDetailAccessMixin(UserPassesTestMixin): | |
def test_func(self, user): | |
""" | |
Tests if user should be allowed access to DetailView if one of two conditions: | |
1. Has staff permissions | |
2. Is the customer associated with the object in a DetailView | |
""" | |
if user.is_staff: | |
return True | |
else: | |
detail_object = self.get_object() | |
return user == detail_object.customer | |
class UserViewMixin(object): | |
def get_object(self, queryset=None): | |
return self.request.user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment