Skip to main content

UNKNOWN

Project description

Compose your permission classes for django-rest-framework.

Usage

To compose a new Permission class to be used by the django rest framework views you have to wrap the original class in a P class then can use the logical operators from python:

  • ~ (not)

  • | (or)

  • & (and)

This package also contains a few permission that can be used.

For example, when we want to create a permission class that allows read access to authenticated users and write access to superusers we can use the following code:

from rest_framework.permissions import IsAuthenticated
from drf_composable_permissions.p import P
from drf_composable_permissions.permissions import IsReadOnly, IsSuperuser

MyPermission = P(IsSuperuser) | (P(IsAuthenticated) & P(IsReadOnly))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-composable-permissions-0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distributions

drf_composable_permissions-0.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

drf_composable_permissions-0.1-py2-none-any.whl (5.0 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page