Files
mandelstudio/mandelstudio/settings/base.py

164 lines
5.2 KiB
Python

"""
Django settings for de tilde project.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import importlib.util
import sys
from pathlib import Path
from configtype.jsonconfig import setup_search_paths
_project_app_path = Path(__file__).parent.parent
BASE_PATH = _project_app_path.parent
BASE_DIR = str(BASE_PATH)
setup_search_paths("/etc/ocyan/", str(_project_app_path))
from ocyan.main.settings import * # noqa: I001 # pylint:disable=W0401,W0614
from ocyan.core.fender import config as ocyan_config # noqa: I001
# Ensure repo-level template overrides are picked up in every environment
# (staging/prod often deploy the project as a checkout rather than a wheel).
_project_templates_dir = str(BASE_PATH / "templates")
if "TEMPLATES" in globals() and TEMPLATES and isinstance(TEMPLATES[0], dict):
TEMPLATES[0].setdefault("DIRS", [])
if _project_templates_dir not in TEMPLATES[0]["DIRS"]:
TEMPLATES[0]["DIRS"].insert(0, _project_templates_dir)
INSTALLED_APPS = [
"mandelblog_content_guard.apps.MandelblogContentGuardConfig",
"mandelstudio",
] + INSTALLED_APPS
# Never allow demo-data plugins in this production project context.
def _is_demo_data_app(app_label: str) -> bool:
normalized = "".join(ch for ch in app_label.lower() if ch.isalnum())
return "demodata" in normalized
INSTALLED_APPS = [app for app in INSTALLED_APPS if not _is_demo_data_app(app)]
# Route through the project URL layer so MandelStudio can override
# sitemap/robots behavior while still delegating the main Ocyan routes.
ROOT_URLCONF = "mandelstudio.urls"
def _ensure_required_app(*candidates):
"""Ensure required plugin apps remain enabled when /etc/ocyan config omits them."""
if any(app in INSTALLED_APPS for app in candidates):
return
for app in candidates:
if importlib.util.find_spec(app):
INSTALLED_APPS.append(app)
return
_ensure_required_app(
"ocyan.plugin.carbasa.carbasa",
"ocyan.plugin.carbasa",
)
_ensure_required_app(
"ocyan.plugin.coyote.coyote",
"ocyan.plugin.coyote",
)
def _ensure_installed_app(app_label: str, *, before: str | None = None) -> None:
"""Ensure an app is present in INSTALLED_APPS with optional ordering."""
if app_label in INSTALLED_APPS:
INSTALLED_APPS.remove(app_label)
if before and before in INSTALLED_APPS:
INSTALLED_APPS.insert(INSTALLED_APPS.index(before), app_label)
else:
INSTALLED_APPS.append(app_label)
# Prefer Carbasa's webshop templates whenever Oscar is enabled.
# Ensures the full Carbasa webshop header (search, user bar, cart, megamenu),
# even when the environment doesn't mark the site as a webshop explicitly.
_oscar_enabled = any("ocyan.plugin.oscar" in app for app in INSTALLED_APPS)
if _oscar_enabled and importlib.util.find_spec("ocyan.plugin.carbasa.webshop"):
_ensure_installed_app("ocyan.plugin.carbasa.webshop", before="ocyan.plugin.carbasa")
# Keep Carbasa/Coyote defaults stable even when plugin settings are not
# injected early enough during startup on this deployment.
OXYAN_HEADER_OPTIONS = globals().get(
"OXYAN_HEADER_OPTIONS",
[
("basic", "Basic Header"),
("big", "Big Header"),
("mega", "Mega Header"),
],
)
COMPRESS_CACHE_KEY_FUNCTION = globals().get(
"COMPRESS_CACHE_KEY_FUNCTION",
"ocyan.plugin.coyote.utils.get_compressor_cache_key",
)
OXYAN_LAZY_THEME_DEFINITIONS = globals().get(
"OXYAN_LAZY_THEME_DEFINITIONS",
"ocyan.plugin.coyote.definitions.get_coyote_definitions",
)
# Enable request language negotiation.
if "django.middleware.locale.LocaleMiddleware" not in MIDDLEWARE:
if "django.contrib.sessions.middleware.SessionMiddleware" in MIDDLEWARE:
idx = (
MIDDLEWARE.index("django.contrib.sessions.middleware.SessionMiddleware") + 1
)
MIDDLEWARE.insert(idx, "django.middleware.locale.LocaleMiddleware")
else:
MIDDLEWARE.insert(0, "django.middleware.locale.LocaleMiddleware")
LANGUAGE_CODE = "nl"
LANGUAGES = [
("nl", "Nederlands"),
("en", "English"),
("de", "Deutsch"),
("fr", "Français"),
("es", "Español"),
("it", "Italiano"),
("pt", "Português"),
("ru", "Русский"),
]
STATIC_ROOT = str(BASE_PATH / "static")
MEDIA_ROOT = str(BASE_PATH / "media")
PRIVATE_MEDIA_ROOT = str(BASE_PATH / "private")
DATABASES = {
"default": {
"ENGINE": "ocyan.i18n.db.sqlite3",
"NAME": str(BASE_PATH / "db.sqlite3"),
}
}
SECRET_KEY = "xyh998+wzhzueld8u6=)l@imh^!07&c6i_hjn7=8=jl$8%z_4t"
# Template engine vertical preset
ACTIVE_VERTICAL = "agency"
# Wagtail content internationalization in admin
WAGTAIL_I18N_ENABLED = True
WAGTAIL_CONTENT_LANGUAGES = LANGUAGES
CONTENT_GUARD_STRICT = True
CONTENT_GUARD_BLOCK_MEDIUM = False
CONTENT_GUARD_LOCALES = [code for code, _label in LANGUAGES]
CONTENT_GUARD_REWRITE_ENABLED = True
CONTENT_GUARD_REWRITE_BACKEND = None
if "test" in sys.argv:
MIGRATION_MODULES = globals().get("MIGRATION_MODULES", {}).copy()
MIGRATION_MODULES["template_engine"] = (
"mandelstudio.test_migrations.template_engine"
)
TEST_RUNNER = "django.test.runner.DiscoverRunner"