django-groups-cache
Caches the groups a user is in so requests don’t have to make calls to the database to check group status.
Support
Currently supporting Django 1.8, 1.11, and 2.0 with Python 2.7/Python 3 where support for versions aligns with Django’s support. See the tox.ini file for specific Python and Django version pairings.
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',
)
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 %}
Turn on caching:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
See https://docs.djangoproject.com/en/1.10/topics/cache/#memcached for more details on setting up memcached.
Note**
Using django.core.cache.backends.locmem.LocMemCache is not safe for production unless you are only running a single process (and odds are you aren’t).
See https://docs.djangoproject.com/en/1.10/topics/cache/#local-memory-caching for more details.
Features
Adds groups_cache property to request object
Provides templatetag has_group
Invalidates cache on User or Group model changes and on m2m groups ManyToManyField changes
Fully tested with high coverage
Running Tests
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.5.5 (2017-01-13)
Bug fix for templatetag has_group
Tests added for 100% coverage of templatetag folder
0.5.5 (2017-01-12)
Omit urls.py from coverage report (not used but needed for django package)
Omit apps.py from coverage report (default apps file)
0.5.4 (2017-01-12)
Removal of py32/django1.8 support from Travis CI build
0.5.3 (2017-01-12)
Fixing .travis.yml file and CI builds
0.5.2 (2017-01-12)
Typo in README.rst
0.5.1 (2017-01-12)
Add codecov.io support
Documentation updates
0.5.0 (2017-01-12)
Add requirements.txt to tox.ini so tests can run
Fix broken compatibility with Django 1.8/1.9 due to backwards incompatible changes in 1.9/1.10 code
0.4.0 (2017-01-12)
Add test suite that generates 100% coverage
Fixed a bug found by test suite with cache not invalidating on the groups ManyToManyField changing
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.
Metadata
Release files for django-groups-cache 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-groups-cache-1.0.2.tar.gz | 8.1 kB | Without provenance | Details for django-groups-cache-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_groups_cache-1.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_groups_cache-1.0.2-py2.py3-none-any.whl |
Total release size: 18.5 kB
Release files / django-groups-cache-1.0.2.tar.gz
| Download URL | django-groups-cache-1.0.2.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5b8621c2e18f5067cdbb289f9a35616539a351794cc27dbc8b6bf8dd34ac856
|
|
BLAKE2b-256 checksum How to use checksums |
c9262c6fc2d80de0c1a84591e470edab2bc8d739bdfc68cc2d24d375ae195150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_groups_cache-1.0.2-py2.py3-none-any.whl
| Download URL | django_groups_cache-1.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
349e03fc1371f7292f70682792d8d0d8f8731765e2dd8ffdfb4888d161238cec
|
|
BLAKE2b-256 checksum How to use checksums |
c1d5c72d95a2b649357c1f779a23dc6872494112aacb89fbafaf9d71cb3a3873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-groups-cache 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.