Caches the groups a user is in so requests don't have to make calls to the database to check group status.
Project description
Caches the groups a user is in so requests don’t have to make calls to the database to check group status.
Documentation
The full documentation is at https://django-groups-cache.readthedocs.io.
Quickstart
Install django-groups-cache:
pip install django-groups-cache
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'groups_cache.apps.GroupsCacheConfig',
...
)
Add the middleware to your MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'groups_cache.middleware.GroupsCacheMiddleware',
)
Features
Adds groups_cache property to request object
Provides templatetag has_group
Invalidates cache on User or Group model changes
Checking in a Django Template if the user is in a group name:
{% if "admins" in request.groups_cache %}
<a href="/admin">Admin Panel</a>
{% endif %}
# or use templatetag, note that templatetag is slower
{% load has_group %}
{% if request.user|has_group:"admins" %}
<a href="/admin">Admin Panel</a>
{% endif %}
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.3.1 (2017-01-11)
Documentation updates
0.3.0 (2017-01-11)
First stable and working release on PyPI.
0.1.0 (2017-01-11)
First release on PyPI.
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
File details
Details for the file django-groups-cache-0.3.1.tar.gz
.
File metadata
- Download URL: django-groups-cache-0.3.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5deca5e840440720992465b3ac5cfdacab7a9d1c074942aa50f9e40669e7c33 |
|
MD5 | b3a5bd599cd714649019ec825d8b19e9 |
|
BLAKE2b-256 | a6de52feff27ef3a4330283169a1764acbc5ab355e3f10aeee292187bc19adb5 |