[settings] more robust detection of deployment

Retrieve it only once from env, make it an uppercase string
This commit is contained in:
bronsen 2025-03-15 21:55:43 +01:00
parent e175071d3b
commit 4d96f60b46

View file

@ -15,7 +15,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env(
DEBUG=(bool, False),
DEPLOYMENT=(str, "Dev"),
DEPLOYMENT=(str, "DEV"),
)
env.read_env(env.str("ENV_PATH", BASE_DIR / ".env")) # pyright: ignore[reportArgumentType]
@ -23,6 +23,7 @@ env.read_env(env.str("ENV_PATH", BASE_DIR / ".env")) # pyright: ignore[reportAr
SECRET_KEY = env("SECRET_KEY")
DEBUG = env("DEBUG")
DEPLOYMENT = str(env("DEPLOYMENT")).upper()
ALLOWED_HOSTS = []
SESSION_COOKIE_SECURE = True
@ -39,7 +40,7 @@ INSTALLED_APPS = [
"django.contrib.staticfiles",
"collector.apps.CollectorConfig",
]
if env("DEPLOYMENT") == "Dev":
if DEPLOYMENT == "DEV":
INSTALLED_APPS += [
"django_extensions",
"debug_toolbar",
@ -55,7 +56,7 @@ MIDDLEWARE = [
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
if env("DEPLOYMENT") == "Dev":
if DEPLOYMENT == "DEV":
MIDDLEWARE += [
"debug_toolbar.middleware.DebugToolbarMiddleware",
]