custom-user-roles-1.1.0
توضیحات
Simple role-based user permissions for Django.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | custom-user-roles-1.1.0 |
| نام | custom-user-roles |
| نسخه کتابخانه | 1.1.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Diogo Laginha |
| ایمیل نویسنده | diogo.laginha.machado@gmail.com |
| آدرس صفحه اصلی | https://github.com/laginha/django-user-roles |
| آدرس اینترنتی | https://pypi.org/project/custom-user-roles/ |
| مجوز | MIT |
Basic Usage
------------
Add ``userroles`` do `INSTALLED_APPS`
::
INSTALLED_APPS = (
...
'userroles',
)
Add the ``USER_ROLES`` setting
::
USER_ROLES = (
'manager',
'moderator',
'client',
)
Define your Custom User model (optional)
::
AUTH_USER_MODEL = 'custom_user.EmailUser'
Add subroles for any of the roles defined in the `USER_ROLES` setting (optional)
::
MANAGER_ROLES = (
'staff_manager', 'business_manager'
)
Subroles can have sub-subroles and so on. But be careful not to repeat the names!
The `role_required` decorator provides similar behavior to Django's `login_required` and `permission_required` decorators. If the user accessing the view does not have the required roles, they will be redirected to the login page.
::
from userroles.decorators import role_required
@role_required('manager', 'moderator')
def view(request):
...
or
::
from userroles.decorators import role_required
from userroles import roles
@role_required(roles.manager, roles.moderator)
def view(request):
...
If user has a subrole of the required role, it passes de user test as well!
نحوه نصب
نصب پکیج whl custom-user-roles-1.1.0:
pip install custom-user-roles-1.1.0.whl
نصب پکیج tar.gz custom-user-roles-1.1.0:
pip install custom-user-roles-1.1.0.tar.gz