Skip to content

Instantly share code, notes, and snippets.

@andreyshuster
Created December 3, 2014 12:04
Show Gist options
  • Save andreyshuster/0b99ef2b30779fd01649 to your computer and use it in GitHub Desktop.
Save andreyshuster/0b99ef2b30779fd01649 to your computer and use it in GitHub Desktop.
user_passes_test class based
# http://stackoverflow.com/questions/8082670/django-user-passes-test-decorator
class SuperuserRequiredMixin(object):
@method_decorator(user_passes_test(lambda u: u.is_superuser))
def dispatch(self, *args, **kwargs):
return super(SuperuserRequiredMixin, self).dispatch(*args, **kwargs)
class MyView(SuperuserRequiredMixin, View):
def get(self, request):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment