Files
gaehsnitz/gaehsnitzproject/settings.py
T
flo 4c9d041254 Add year-scoped drink data, UserPayment model, German verbose names
Drink gets a year field (default 2024 for legacy rows), with name+year
unique together so each festival can have its own price/crate config
without overwriting the previous year. User balance properties
(consumed_drinks_price, paid_amount, open_balance) and the new
current_year() helper all filter by current year so year-over-year data
stays separated.

UserPayment model tracks per-user payments (cash/PayPal/bank/other)
against their drink tab, separate from Donation (event-level income).

Verbose names + Meta verbose_name(_plural) added across all models, and
LANGUAGE_CODE set to "de" so the admin renders German throughout.

Drink gains a few derived properties (crates_full_returned,
crates_remaining, bottles_consumed, bottles_remaining,
remaining_purchase_value) used by the upcoming admin and dashboard
views.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 22:18:57 +02:00

112 lines
3.2 KiB
Python

import os
def _get_env_production_mode():
env_var = os.environ.get("DJANGO_PRODUCTION_MODE", "false")
return env_var.lower() == "true"
def _get_env_secret_key():
env_var = os.environ.get("DJANGO_SECRET_KEY")
assert env_var is not None, "DJANGO_SECRET_KEY environment variable must be set when using production mode"
return env_var
def _get_env_allowed_hosts():
env_var = os.environ.get("DJANGO_ALLOWED_HOSTS")
assert env_var is not None, "DJANGO_ALLOWED_HOSTS environment variable must be set when using production mode"
return [host.strip() for host in env_var.split(",")]
def _get_env_static_root():
env_var = os.environ.get("DJANGO_STATIC_ROOT")
assert env_var is not None, "DJANGO_STATIC_ROOT environment variable must be set when using production mode"
return env_var
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PRODUCTION = _get_env_production_mode()
if PRODUCTION:
SECRET_KEY = _get_env_secret_key()
DEBUG = False
ALLOWED_HOSTS = _get_env_allowed_hosts()
CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS]
STATIC_ROOT = _get_env_static_root()
else:
SECRET_KEY = "LqKSgoFtED4IFYxf01lBi5MEI4ExSayCakwLjyuzytDJ7vuMq9"
DEBUG = True
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
"gaehsnitz",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": os.environ["DB_HOST"],
"PORT": os.environ["DB_PORT"],
"NAME": os.environ["DB_NAME"],
"USER": os.environ["DB_USER"],
"PASSWORD": os.environ["DB_PASSWORD"],
}
}
DEFAULT_AUTO_FIELD = "django.db.models.SmallAutoField"
ROOT_URLCONF = "gaehsnitzproject.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "gaehsnitzproject.wsgi.application"
TIME_ZONE = "Europe/Berlin"
LANGUAGE_CODE = "de"
USE_I18N = True
USE_L10N = False
USE_TZ = True
STATIC_URL = "/static/"
AUTH_USER_MODEL = "gaehsnitz.User"
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"gaehsnitz.auth_backends.PinBackend",
]
LOGIN_URL = "/suff/"