Implements a function to test whether a given url is currently visible to a given user.
Project description
django_page_visibility
This package implements a standard protocol allowing developers to ask "can user X currently access page Y?".
Rather than duplicating the permission checks performed in that view, you ask the view itself whether or not the user can access it.
Conforming Views
Conforming views must implement a .test_page_visibilty(request, *args, **kwargs)
method. This will be called with the same args
and kwargs
that the actual view would be called with.
This method must return a truthy value if the user can access the page, and False otherwise. It may also raise an exception, to indicate that the user cannot access the page. See PAGE_VISIBILITY_EXCEPTIONS
below.
The Test Function
Developers can call django_page_visibility.is_visible_to_user(path, user)
(see the code for details) to test visibility. Or, in a template, you can use our is_permitted_to_see
filter or permitted_link
tag.
PAGE_VISIBILITY_EXCEPTIONS
setting
By default, we return False
if either django.http.Http404
or django.core.exceptions.PermissionDenied
are raised. You can override this by setting (in your django settings) PAGE_VISIBILITY_EXCEPTIONS
to a list of exception classes.
We expect most users to override this setting. For example, if you are using exceptional_auth
and django_early_return
, then you'll want to set:
PAGE_VISIBILITY_EXCEPTIONS = [
'django.core.exceptions.PermissionDenied',
'django.http.Http404',
'django_early_return.EarlyReturn',
'exceptional_auth.AuthException',
]
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
Built Distribution
File details
Details for the file django_page_visibility-0.1.0.tar.gz
.
File metadata
- Download URL: django_page_visibility-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d6926df81ce28360c389ec094f942ca9d93157d3370bbc379d564142234b447 |
|
MD5 | 1669219239c11c6080b0aae495351f72 |
|
BLAKE2b-256 | aa6d3da328b2acdf0183a0f15597f32cf9e5cc01fd0be27530c32eb2c42e9f41 |
File details
Details for the file django_page_visibility-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: django_page_visibility-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1873d77b4388c196d0faca0708797502d5a908b5b2518fc5a08617f4e027e3fd |
|
MD5 | 77f6da31a274e0a56c4e6796ce933b2c |
|
BLAKE2b-256 | a117cd0c446f5813c8cf8b822e9add041ad5ca842e7afa31a4988d3c60ddd8be |