Use multiple permission classes in django class based views.
Project description
Django multiple permissions
Usage
- Install the package.
$ pip install multiple-permissions
- Add
multiple_permissions
to installed apps.
INSTALLED_APPS = [
...,
"multiple_permissions",
...,
]
- Add
PermissionMiddleware
to MIDDLEWARE list.
MIDDLEWARE = [
...,
"multiple_permissions.middlewares.PermissionMiddleware",
]
- Set
permission_classes
attribute to view classes.
from django.views.generic import ListView, CreateView
from multiple_permissions.permissions import IsAuthenticated, IsSuperuser, IsManager
class PollsListView(ListView):
multiple_permissions = (IsAuthenticated,)
...
class PollsCreateView(CreateView):
multiple_permissions = (IsSuperuser, IsManager)
...
Creating new permissions
-
create new file in your apps named
permissions.py
and write the followng code -
note that your user should have
is_manager
attribute or model field otherwise you'll catch AttributeError
from multiple_permissions.permissions import BasePermission
class IsManager(BasePermission):
def has_permission(self, request, view=None):
if request.user.is_authenticated and request.user.is_active and request.user.is_manager:
return True
return False
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for multiple_permissions-0.1.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b639dc43bb1769cbcc946a6708237017501fd5fc250c201fd0fe5366b778e142 |
|
MD5 | e268622497b1b71c977dcade6804dd11 |
|
BLAKE2b-256 | 0188be3ece591045e3641ed3b13279a9dc58655707d74043b0608ed5099a3acb |
Close
Hashes for multiple_permissions-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae22b3c2bca4f28daaa278d10350a993da6a9972de3c7ba0ce361f8250eb617 |
|
MD5 | 7982c398cb06773e70b69aa79b42de37 |
|
BLAKE2b-256 | 66c463b36b1dae5c5600cf056acb6d96d575bf4f2c8da7658f05493d57ae4c9b |