Simple role-based user permissions for Django.
Project description
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!
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 Distribution
Close
Hashes for custom_user_roles-1.0.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac8a578edd0410729f09e6859bfdedb4d1c0acc75c264da885d698df37e197ff |
|
MD5 | e78c959cd64f61b989a1ed2029e11fde |
|
BLAKE2b-256 | 296831a0e08ee6e658e224076b0b8cc9e1bd8b13c82d4e0b7f7a6432c07b6cf8 |