""" Django-Einstellungen für den Netzwerk Planer. Alle umgebungsabhängigen Werte kommen aus der `.env` (Vorlage: `.env.example`). """ import os from pathlib import Path from django.core.exceptions import ImproperlyConfigured from dotenv import load_dotenv BASE_DIR = Path(__file__).resolve().parent.parent load_dotenv(BASE_DIR / ".env") def env_bool(name, default=False): return os.getenv(name, str(default)).strip().lower() in ("1", "true", "yes", "ja") def env_list(name, default=""): return [v.strip() for v in os.getenv(name, default).split(",") if v.strip()] # --- Sicherheit ------------------------------------------------------------- SECRET_KEY = os.getenv("DJANGO_SECRET_KEY") if not SECRET_KEY: raise ImproperlyConfigured("DJANGO_SECRET_KEY fehlt – siehe .env.example") DEBUG = env_bool("DJANGO_DEBUG", False) ALLOWED_HOSTS = env_list("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1") CSRF_TRUSTED_ORIGINS = env_list("DJANGO_CSRF_TRUSTED_ORIGINS") # --- Anwendungen ------------------------------------------------------------ INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", # Projekt-Apps "inventar", "topologie", "export", "scanner", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "config.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [BASE_DIR / "templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] WSGI_APPLICATION = "config.wsgi.application" # --- Datenbank -------------------------------------------------------------- # SQLite-Datei liegt in DATA_DIR; im Container ist das ein Volume. DATA_DIR = Path(os.getenv("DJANGO_DATA_DIR", BASE_DIR / "data")) DATA_DIR.mkdir(parents=True, exist_ok=True) DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": DATA_DIR / "db.sqlite3", } } DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" # --- Anmeldung -------------------------------------------------------------- AUTH_PASSWORD_VALIDATORS = [ {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"}, {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, ] LOGIN_URL = "login" LOGIN_REDIRECT_URL = "start" LOGOUT_REDIRECT_URL = "login" # --- Sprache und Zeit ------------------------------------------------------- LANGUAGE_CODE = "de-de" TIME_ZONE = "Europe/Berlin" USE_I18N = True USE_TZ = True # --- Statische Dateien ------------------------------------------------------ STATIC_URL = "static/" STATICFILES_DIRS = [BASE_DIR / "static"] STATIC_ROOT = BASE_DIR / "staticfiles" STORAGES = { "default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}, "staticfiles": {"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage"}, }