Skip to main content

Implementation of permissions not related to models

Project description

# Django Global Permissions

Implementation of permissions not related to models

# Quickstart

Install django-global-permissions:

```
pip install django-global-permissions
```

Add to the installed apps:

```python
INSTALLED_APPS += (global_permissions,)
```

If you want co create a permission in the admin interface, then head to
the Global Permissions section, then add a permission. Pick a name (which
should be a human readable description), a code name (which will be used throughout
the your apps), then save it.

Then open the user edit page. Now you can choose the permission you've just created.

Otherwise if you want to create a permission programmatically, just import the GlobalPermission
model and create a new permission choosing a name and a codename.

```python
from global_permissions.models import GlobalPermission

GlobalPermission.objects.create(name='My Perm', codename='my_perm')
```

## Putting into action!

Lets say you want to verify if the logged in user can do something (based on a permission).
In your view, you can do the following

```python
if user.has_perm('global_permissions.my_perm_codename'):
pass # do something intersting!
else:
pass # ops, you're not allowed to do that. Sorry ¯\_(ツ)_/¯
```

If you cant to verify a permission inside some template, you can do this way:

```htmldjango
{% if perms.global_permissions.my_perm_codename %}
Yay!
{% else %}
Not so lucky...
{% endif %}
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-global-permissions-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file django-global-permissions-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-global-permissions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4351d73c7ac1bf4236ad181e2df69c1b592eff9dc55f5bd6451697bf93a079e1
MD5 cba70f657a7bd2da7c74d2ef40079b00
BLAKE2b-256 a8995cc9d5f034722761c4cb196f0f5f8b7b4a80a14b197606330b015893a185

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page