Use multiple permission classes in django class based views.
Project description
Django multiple permissions
Usage
- install package
$ pip install multiple-permissions
- add apps.core to installed apps
INSTALLED_APPS = [
...,
"multiple_permissions",
...,
]
- add apps.core.middlewares to MIDDLEWARE list
MIDDLEWARE = [
...,
"multiple_permissions.middlewares.PermissionMiddleware",
]
- Add "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
File details
Details for the file multiple_permissions-0.1.8.tar.gz
.
File metadata
- Download URL: multiple_permissions-0.1.8.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5589a3fdcea2a2cf89531e2bc293776ce7247ab8a1008b200da4a093fdf332a7 |
|
MD5 | fae5f09221bdd6bafe0e3e28814a6560 |
|
BLAKE2b-256 | 3f1649a86f5ee0d6d78799796d2cd1d77ec3bde29f61d9c961a485cf38d5616a |
File details
Details for the file multiple_permissions-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: multiple_permissions-0.1.8-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 401eb9f2e52f013ffae3da087dc6fe3d4dbba4910bbf286e2ac36a91e14c5ab0 |
|
MD5 | 977a09914cdc9252d7d901bc2bc7628c |
|
BLAKE2b-256 | 524411e61047a03966a26d531a02ece38053a75c1e503678fb7ba29a588d104d |