Skip to main content

Multisite support for feincms3

Project description

CI Status

Multisite support for feincms3.

Usage scenario

Suppose you have a website with several domains and languages but an exact 1:1 mapping between them. Django offers the django.contrib.sites application to partition data but you still have to run one webserver per site.

This app offers a feincms3 abstract page model, a middleware and utilities to support this scenario. Contrary to feincms3-sites which is even more flexible and allows arbitrary combinations of languages and domains this app only allows exactly one domain per language and exactly one language per domain.

Installation

  • Install the package using pip install feincms3-language-sites into an environment where you’re already using feincms3 pages.

  • Extend feincms3_language_sites.models.AbstractPage instead of feincms3.pages.AbstractPage. This abstract page already extends feincms3.mixins.LanguageAndTranslationOfMixin so you may remove the language mixins (if you have added them before).

  • Replace the LocaleMiddleware with feincms3_language_sites.middleware.site_middleware. In case you’re using feincms3 applications you should ensure that the site_middleware is added before feincms3.applications.apps_middleware.

  • Optionally add feincms3_language_sites.middleware.redirect_to_site_middleware if you want to enforce the host. The SECURE_SSL_REDIRECT is also respected. The redirect_to_site_middleware has to be added before the SecurityMiddleware otherwise users may get redirected twice in a row.

  • Configure the sites.

Configuration

Possible configuration:

SITES = {
    "de": {
        "host": "127.0.0.1:8000",
        "host_re": r"example\.com$|127.0.0.1:8000$",
    },
    "fr": {
        "host": "localhost:8000",
    },
}

Sites are checked in the order they are declared (since dictionaries are guaranteed to preserve the ordering of keys since Python 3.7).

The keys of the SITES dictionary have to be equal to all language codes in LANGUAGES. The host is required and should only consist of the host and an optional port, nothing else. The host_re is automatically derived from host if it isn’t given explicitly and is matched against request.get_host() to find the current site. If no host_re matches the site_middleware automatically raises a DisallowedHost exception (which produces the same error as Django if the request doesn’t match ALLOWED_HOSTS).

Utilities

  • feincms3_language_sites.models.site_for_host

  • feincms3_language_sites.models.reverse_language_site_app

  • feincms3_language_sites.templatetags.feincms3_language_sites.site_translations

Notes

Note that Page.objects.active() only returns pages in the current language. If you want to generate translation links (e.g. using ...|translations in a template) you do not want to use the .active() queryset method but build something yourself which runs .filter(is_active=True).

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

feincms3_language_sites-0.0.9.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

feincms3_language_sites-0.0.9-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file feincms3_language_sites-0.0.9.tar.gz.

File metadata

  • Download URL: feincms3_language_sites-0.0.9.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for feincms3_language_sites-0.0.9.tar.gz
Algorithm Hash digest
SHA256 b0c5810d7f87bd9728d7131bbae2841ad0e77aa84ba2d7a5060ed23b524af91d
MD5 071aa4bbaebb8ee58dccb92e5e5da4c8
BLAKE2b-256 0a4338e54db319c787665e6b7c0670c68c87e6f76d5ea1c788afa08396bfb4e9

See more details on using hashes here.

File details

Details for the file feincms3_language_sites-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: feincms3_language_sites-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for feincms3_language_sites-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0f5f1375b32b2dd974eb60bfc8029f49d9245d82e30dac298b0d79b2eb39b14a
MD5 8b1c003bc7715fc88d35485e98d962a5
BLAKE2b-256 a503f3ea6f4075a8845fb3285bed09017f0a0c7ae9b4b025c90ebaba36bcc8ca

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