Django authentication and authorization utilities
Project description
Django authentication and authorization utilities.
Installation
pip install django-auth-utils
Supported and tested on:
Python: 2.7, 3.4, 3.5, PyPy
Django: 1.8, 1.9
Configuration
In order to use the auth_utils template tag library, add auth_utils to your INSTALLED_APPS.
Alternatively, since Django 1.9, you can add auth_utils.templatetags.auth_utils to your DjangoTemplates OPTIONS.
Usage
Permission-checking views
The ObjectPermissionRequiredMixin view combines Django’s PermissionRequiredMixin and SingleObjectMixin views, and performs the permission check against the object that was looked up.
Use it like the base classes:
from auth_utils.views import ObjectPermissionRequiredMixin
class ArticleDetail(ObjectPermissionRequiredMixin, generic.DetailView):
model = Article
permission_required = ['news.read_article']
class ArticleUpdate(ObjectPermissionRequiredMixin, generic.UpdateView):
model = Article
permission_required = ['news.change_article']
Permission-checking in templates
Load the template tag library:
{% load auth_utils %}
The perms filter allows checking object-level permissions with a convenient syntax:
{% if perm in user|perms:object %} ... {% endif %}
The object argument is optional. If omitted, the global permission is checked, similar to Django’s perms object.
Examples:
{% if 'news.read_article' in user|perms:article %}
{{ article.text }}
{% else %}
You do not have permission to read this article.
{% endif %}
{% if 'news.change_article' in user|perms:article %}
<a href="...">Edit article</a>
{% endif %}
{% if 'news.delete_article' in user|perms:article %}
<a href="...">Delete article</a>
{% endif %}
The library provides can_change and can_delete shorthands for checking Django’s default app.change_model and app.delete_model model permissions:
{% if user|can_change:article %} <a href="...">Edit</a> {% endif %}
{% if user|can_delete:article %} <a href="...">Delete</a> {% endif %}
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 Distributions
File details
Details for the file django-auth-utils-0.1.tar.gz
.
File metadata
- Download URL: django-auth-utils-0.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9fd42554f41f69053c072635e56e0c10a2ef4648d1a4c3827bc2fcaa53dee2a |
|
MD5 | aae05da74cdf70ad98474567ff0b96aa |
|
BLAKE2b-256 | dc2148fc01cce3bbc50811fbbc890292228b17757fd2b747fc4bc9b6aaf6fd2a |
File details
Details for the file django_auth_utils-0.1-py3-none-any.whl
.
File metadata
- Download URL: django_auth_utils-0.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c9531c0f4364a808ca559b45ab71a152d5fe81be0b9f6482d69fd93143c9c88 |
|
MD5 | 42fef9595b795e97f0973f0b43118fc3 |
|
BLAKE2b-256 | 3ea24bb87db1ab0c600c62c2ef97ff4a5d7988ddb8c9e3dde366e03b05adf1ac |
File details
Details for the file django_auth_utils-0.1-py2-none-any.whl
.
File metadata
- Download URL: django_auth_utils-0.1-py2-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42aff2b3f78cb672da77189f57530fed65113cdd921f194ba5a45207f9bf32d6 |
|
MD5 | 38a7cf71ca47e84cc8e5da5ddb3a45e5 |
|
BLAKE2b-256 | f6b13fae9a4dd984d3dc44378d01f94ee3208fbbaa30ecda0484a1d995d6c2fc |