Skip to main content

Implementation of permissions not related to models

Project description

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.

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.2.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_global_permissions-0.2.5-py2.py3-none-any.whl (5.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: django-global-permissions-0.2.5.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-global-permissions-0.2.5.tar.gz
Algorithm Hash digest
SHA256 3edbf03260ee4c6ee1a0f697921d94e634a319ca462721d611fc6f71de2611c7
MD5 9e5dfe0145d9d5a94f34982749f452b8
BLAKE2b-256 cd43aa20163717e0bf1616f6eed89410122b54b8b0ae39aad9d7fd73ba3cb547

See more details on using hashes here.

File details

Details for the file django_global_permissions-0.2.5-py2.py3-none-any.whl.

File metadata

  • Download URL: django_global_permissions-0.2.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for django_global_permissions-0.2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45e6d604ec3f9d4ed9508f4a8d278c9ced83f60020c4d67e85b90eed2c6105d2
MD5 ed8f94d39470650f80506cae242e9bce
BLAKE2b-256 b46cbe334cb4a6f8bd45816b359ecb7d9609bd16cd8a8fe899c715fe3d761098

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