Skip to main content

Custom extensions for the Django sites framework

Project description

Part of edX code.

edx-django-sites-extensions CI Codecov

This package includes extensions to the Django “sites” framework used by Open edX Django IDAs (independently deployable applications).

Overview

In order to support multitenancy in an IDA, it is helpful to make use of the Django “sites” framework.

One shortcoming of the Django “sites” framework is the fact that the CurrentSiteMiddleware provided by the framework that adds the current site to incoming requests does not allow you to fall back to a site that you can configure in settings in case the current site cannot be determined from the host of the incoming request.

The Django app provided by this package overcomes this issue by monkey patching the django.contrib.sites.models.SiteManager.get_current() function which is called by the CurrentSiteMiddleware to determine the current site. The patched version of this function will first try to determine the current site by checking the host of the incoming request and attempting to match a site by domain. If a site cannot be found this way, it will fall back to the default site configured by setting the SITE_ID setting.

Another issue with the Django “sites” framework is that it uses an in-memory cache of Site models which makes it difficult to update models associated with the Site model via Django admin and have those updates be reflected across all Python processes in a multi-process application environment.

Again the Django app provided by this package monkey patches the private SiteManager query functions that implement the in-memory caching mechanism to add a configurable timeout to the Site cache allowing model updates to be reflected across all processes after the specified timeout.

To enable this functionality in your Django project:

Install this package in your python environment
$ pip install edx-django-sites-extensions

Add django.contrib.sites.middleware.CurrentSiteMiddleware to your MIDDLEWARE_CLASSES list.

Set the SITE_ID setting:

SITE_ID = 1

This package also provides a mechanism for settings up URL redirects for your application. It makes use of the Django redirects app and provides middleware which will check for Redirect models whose old_path field matches the path of the incoming request and redirects those requests to the new_path of the Redirect model.

To enable this functionality in your Django project:

Install this package in your python environment
$ pip install edx-django-sites-extensions

Add django_sites_extensions.middleware.RedirectMiddleware to your MIDDLEWARE_CLASSES list.

You can then use Django admin to create Redirect models.

Documentation

The docs for edx-django-sites-extensions are on Read the Docs: https://edx-django-sites-extensions.readthedocs.org.

License

The code in this repository is licensed under LICENSE_TYPE unless otherwise noted.

Please see LICENSE.txt for details.

How To Contribute

Contributions are very welcome.

Please read How To Contribute for details.

Reporting Security Issues

Please do not report security issues in public. Please email security@openedx.org.

Mailing List and IRC Channel

You can discuss this code in the edx-code Google Group.

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

edx_django_sites_extensions-6.0.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

edx_django_sites_extensions-6.0.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file edx_django_sites_extensions-6.0.0.tar.gz.

File metadata

File hashes

Hashes for edx_django_sites_extensions-6.0.0.tar.gz
Algorithm Hash digest
SHA256 4e201cf00fbfe4974b73752f6873c86da4c70b1b6c280bd226e69fefbeac08cd
MD5 1a283f289dc29769107569e4f3a0dd10
BLAKE2b-256 6f69fb469fdb7f772261d5e820734d2b92f38f35b1979bb6cebccfc792028e7c

See more details on using hashes here.

File details

Details for the file edx_django_sites_extensions-6.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for edx_django_sites_extensions-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebb4e90a498ec212e55bbd33d1828db4941ca1bee24fddbc17a67a02e916665d
MD5 bb0e81eb02b98e9ad28ca46d10fe2b2e
BLAKE2b-256 0886394b36ed51711ae8cca9bdb8506f64e449b5fbbb7e729fda652244442268

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