django-role
Пакет включает в себя:
- Модель пользователя с ролью вместо групп
- Виджет для выбора прав
Роль в отличии от групп связана с моделю пользователя связью Один ко многим
Установка
pip install django-role
poetry add django-role
Использование модели пользователя
models.py
from user_role.models import AbstractUser
class User(AbstractUser):
...
settings.py
AUTH_USER_MODEL = "app_name.User"
Использование виджета для выбора прав
settings.py
PERMISSIONS_LABELS = {
"add": "Добавление",
"change": "Изменение",
"view": "Просмотр",
"delete": "Удаление",
}
forms.py
from django import forms
from django.contrib.auth.models import Permission
from django.utils.translation import gettext_lazy as _
from user_role.models import Role
from user_role.widgets import PermissionsSelectMultiply
class RoleCreationForm(forms.ModelForm):
permissions = forms.ModelMultipleChoiceField(
label=_("Permissions"),
widget=PermissionsSelectMultiply(),
queryset=Permission.objects.all()
)
class Meta:
model = Role
fields = [
"name",
"permissions"
]
Группирование прав и настройка виджета
class MyPermissionsSelectMultiply(PermissionsSelectMultiply):
groups_permissions = {
"Безопасность": ["user_role.user", "user_role.role"]
}
Metadata
Release files for django-role 0.1.6
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 | Actions |
|---|---|---|---|---|
| django_role-0.1.6.tar.gz | 8.7 kB | Without provenance | Details for django_role-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_role-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for django_role-0.1.6-py3-none-any.whl |
Total release size: 21.9 kB
Release files / django_role-0.1.6.tar.gz
| Download URL | django_role-0.1.6.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5916ce3f66439ddfdc05e57fb98ba3bcecada1764f3dbb641543b9094809c11
|
|
BLAKE2b-256 checksum How to use checksums |
dfaa67ff54694a5154ad4dbd79ad365635054b6d1e8aafcb473ec8e3818be308
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1034-azure
|
Release files / django_role-0.1.6-py3-none-any.whl
| Download URL | django_role-0.1.6-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4378b380e461a058b4bf135d167e18fb1ed2ef15ef14f8a74c61d2dce4d2b8ac
|
|
BLAKE2b-256 checksum How to use checksums |
e831f2e007e0c0eaf5d021da301cf781364b722dad28aa903b16d2ea22f7132e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1034-azure
|
Security for django-role 0.1.6
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.