django-auth-utils
Django authentication and authorization utilities.
Installation
pip install django-auth-utils
Supported and tested on:
Python: 2.7, 3.4, 3.5, 3.6, PyPy, PyPy3
Django: 1.8, 1.10, 1.11
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 %}
Metadata
Release files for django-auth-utils 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-auth-utils-0.1.1.tar.gz | 12.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_auth_utils-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 22.1 kB
Release files / django-auth-utils-0.1.1.tar.gz
| Download URL | django-auth-utils-0.1.1.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
735cee46eef1ad82e43394d405f4fe678e2af9123cd7f270ce07d0615330e51a
|
|
BLAKE2b-256 checksum How to use checksums |
3cacff3c6ed433ea5d8b85f686c09ece258020d022a84b069c08cdefd43b9434
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_auth_utils-0.1.1-py2.py3-none-any.whl
| Download URL | django_auth_utils-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0064eea83a530da6d89adbc84b4e357c82eef6086ce620028e977918d530dcf7
|
|
BLAKE2b-256 checksum How to use checksums |
c9ce830e1f303440c4d17987462591758d60a75d685f9e8a40d3ac053154781f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-auth-utils 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.