Skip to main content

Django Global Permissions

Build Status

Implementation of permissions not related to models

Quickstart

Install django-global-permissions:

pip install django-global-permissions

Add to installed apps:

INSTALLED_APPS += ('global_permissions',)

If you want to create a permission in the admin interface, then head to the Global Permissions section and click add. Pick a name (which should be human readable), a code name (which will be used throughout your apps), then save it. Open the user edit page and 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.

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

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 want to check a permission in a template, you can do it like this:

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

Upgrade

If you're upgrading from version 0.1.x to version 0.2.x, you have to manually update the old contentttype model attribute to the new one. The following script may do the trick:

from django.contrib.contenttypes.models import ContentType

ContentType.objects.filter(name='global_permission', app_label='global_permissions').update(model='globalpermission')

This change is required on django 1.7+ to avoid a prompt asking if you want to remove staled content types after running a migration.

Metadata

Release files for django-global-permissions 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-global-permissions 0.2.6
File Size Uploaded
django-global-permissions-0.2.6.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-global-permissions 0.2.6
File Interpreter ABI Platform
django_global_permissions-0.2.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.1 kB

Release files / django-global-permissions-0.2.6.tar.gz

Download URL django-global-permissions-0.2.6.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
28f1e9a850bbe0a5b1ac30f1fa19b2008a51dbf7409b5625bfcfc1f8b8fac801
BLAKE2b-256 checksum
How to use checksums
1041799967df3b02a6961f314ee8d31a9fb27f975f4bcbaad11b1ca489fab228
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Release files / django_global_permissions-0.2.6-py2.py3-none-any.whl

Download URL django_global_permissions-0.2.6-py2.py3-none-any.whl
Size 5.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e74c27f76fe23743d82b61796c1f08b4cbb47f29b194b886cba95ef8e440df37
BLAKE2b-256 checksum
How to use checksums
c3ae514da685ebf1b83e0f57066872b87a5953e68c4d5bb77b16af1ffd4d9556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page