Skip to main content

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

django_page_visibility-0.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

django_page_visibility-0.0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file django_page_visibility-0.0.1.tar.gz.

File metadata

  • Download URL: django_page_visibility-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for django_page_visibility-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2b00fbfed45e6dedf01acbdf16b89b3da2c1f617f39ce4a239c33b1d91a64f64
MD5 6c8307a534cbef486e69dc8997378853
BLAKE2b-256 54bc7f1665a5d6bab2491d6666f92c4ea5487e0d667691ea7d5f2cda5c239ba6

See more details on using hashes here.

File details

Details for the file django_page_visibility-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_page_visibility-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for django_page_visibility-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27ce9e69dedc0b7cb7443d51ed9f68105ecc37f2bb39c454819d6075f77df1f0
MD5 5485c6fda226f6791138e4350fc19d7d
BLAKE2b-256 cb9351e8a8cb5c81005566dc8b7dbad08257068e26dcf9598aeac62b3f71e1e0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page