Skip to content

Commit 8f16b0e

Browse files
committed
♻️ refactor: review suggestions
1 parent c5c96b8 commit 8f16b0e

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

backend/.env.example

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
DJANGO_SETTINGS_MODULE={{project_name}}.settings.local
2-
# Label shown in the Django admin header to make the active environment explicit.
3-
ADMIN_ENVIRONMENT_LABEL=Local
4-
ADMIN_ENVIRONMENT_COLOR=#111827
5-
ADMIN_ENVIRONMENT_BACKGROUND_COLOR=#f59e0b
62
CELERY_BROKER_URL=amqp://broker:5672//
73
REDIS_URL=redis://result:6379
84
# Please choose postgres or sqlite as your DB:
95
# DATABASE_URL=postgres://{{project_name}}:password@db:5432/{{project_name}}
106
# DATABASE_URL=sqlite:///db.sqlite3
7+
8+
## Label shown in the Django admin header to make the active environment explicit.
9+
ADMIN_ENVIRONMENT_LABEL=Local
10+
ADMIN_ENVIRONMENT_COLOR=#111827
11+
ADMIN_ENVIRONMENT_BACKGROUND_COLOR=#f59e0b

backend/common/context_processors.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
import logging
12
import os
23

34
from django.conf import settings
45

56

7+
logger = logging.getLogger(__name__)
8+
9+
610
def _default_admin_environment_label():
711
settings_module = getattr(settings, "SETTINGS_MODULE", "") or os.getenv(
812
"DJANGO_SETTINGS_MODULE", ""
913
)
1014
if settings_module:
11-
return settings_module.rsplit(".", maxsplit=1)[-1].replace("_", " ").title()
15+
try:
16+
environment_label = (
17+
settings_module.rsplit(".", maxsplit=1)[-1].replace("_", " ").title()
18+
)
19+
if not environment_label:
20+
raise IndexError
21+
return environment_label
22+
except IndexError:
23+
logger.warning(
24+
"Could not determine admin environment label from SETTINGS_MODULE: %s",
25+
settings_module,
26+
)
27+
return "Unknown"
1228

1329
return "Local"
1430

backend/project_name/settings/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ def base_dir_join(*args):
182182
# Sentry
183183
SENTRY_DSN = config("SENTRY_DSN", default="")
184184
COMMIT_SHA = config("RENDER_GIT_COMMIT", default="")
185-
ADMIN_ENVIRONMENT_LABEL = config("ADMIN_ENVIRONMENT_LABEL", default="")
186-
ADMIN_ENVIRONMENT_COLOR = config("ADMIN_ENVIRONMENT_COLOR", default="#111827")
187-
ADMIN_ENVIRONMENT_BACKGROUND_COLOR = config(
188-
"ADMIN_ENVIRONMENT_BACKGROUND_COLOR", default="#f59e0b"
189-
)
190185

191186
# Fix for Safari 12 compatibility issues, please check:
192187
# https://github.com/vintasoftware/safari-samesite-cookie-issue
@@ -257,3 +252,8 @@ def base_dir_join(*args):
257252
DEFENDER_COOLOFF_TIME = 300 # 5 minutes
258253
DEFENDER_LOCKOUT_TEMPLATE = "defender/lockout.html"
259254
DEFENDER_REDIS_URL = config("REDIS_URL")
255+
256+
# Admin Env Label"
257+
ADMIN_ENVIRONMENT_LABEL = config("ADMIN_ENVIRONMENT_LABEL", default="")
258+
ADMIN_ENVIRONMENT_COLOR = config("ADMIN_ENVIRONMENT_COLOR", default="#111827")
259+
ADMIN_ENVIRONMENT_BACKGROUND_COLOR = config("ADMIN_ENVIRONMENT_BACKGROUND_COLOR", default="#f59e0b")

backend/project_name/settings/production.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135

136136
# Sentry
137137
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()], release=COMMIT_SHA)
138+
139+
# Admin Env Label
138140
ADMIN_ENVIRONMENT_LABEL = config("ADMIN_ENVIRONMENT_LABEL", default="")
139141
ADMIN_ENVIRONMENT_COLOR = config("ADMIN_ENVIRONMENT_COLOR", default="white")
140142
ADMIN_ENVIRONMENT_BACKGROUND_COLOR = config("ADMIN_ENVIRONMENT_BACKGROUND_COLOR", default="red")

0 commit comments

Comments
 (0)