diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f380fbe8..ae6686817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ### Added - ✨(backend) add ServiceProvider #522 +- 💄(admin) allow header color customization #552 ### Fixed diff --git a/src/backend/admin/__init__.py b/src/backend/admin/__init__.py new file mode 100644 index 000000000..27875998d --- /dev/null +++ b/src/backend/admin/__init__.py @@ -0,0 +1 @@ +"""People custom admin site.""" diff --git a/src/backend/admin/apps.py b/src/backend/admin/apps.py new file mode 100644 index 000000000..d6f411a38 --- /dev/null +++ b/src/backend/admin/apps.py @@ -0,0 +1,9 @@ +"""Custom Django admin site application configuration.""" + +from django.contrib.admin.apps import AdminConfig + + +class PeopleAdminConfig(AdminConfig): + """Declare our custom Django admin site.""" + + default_site = "admin.sites.PeopleAdminSite" diff --git a/src/backend/admin/sites.py b/src/backend/admin/sites.py new file mode 100644 index 000000000..e0401c1ce --- /dev/null +++ b/src/backend/admin/sites.py @@ -0,0 +1,15 @@ +"""Custom Django admin site for the People app.""" + +from django.conf import settings +from django.contrib import admin + + +class PeopleAdminSite(admin.AdminSite): + """People custom admin site.""" + + def each_context(self, request): + """Add custom context to the admin site.""" + return super().each_context(request) | { + "ADMIN_HEADER_BACKGROUND": settings.ADMIN_HEADER_BACKGROUND, + "ADMIN_HEADER_COLOR": settings.ADMIN_HEADER_COLOR, + } diff --git a/src/backend/admin/templates/admin/base_site.html b/src/backend/admin/templates/admin/base_site.html new file mode 100644 index 000000000..8139baf1f --- /dev/null +++ b/src/backend/admin/templates/admin/base_site.html @@ -0,0 +1,10 @@ +{% extends "admin/base_site.html" %} + +{% block extrastyle %}{{ block.super }} + +{% endblock %} diff --git a/src/backend/people/settings.py b/src/backend/people/settings.py index 7eb27e8f7..22db4ddba 100755 --- a/src/backend/people/settings.py +++ b/src/backend/people/settings.py @@ -158,7 +158,12 @@ class Base(Configuration): TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(BASE_DIR, "templates")], + "DIRS": [ + os.path.join(BASE_DIR, "templates"), + os.path.join( + BASE_DIR, "admin", "templates" + ), # enforce load before Django's admin + ], "OPTIONS": { "context_processors": [ "django.contrib.auth.context_processors.auth", @@ -200,6 +205,7 @@ class Base(Configuration): # Django's applications from the highest priority to the lowest INSTALLED_APPS = [ # People + "admin.apps.PeopleAdminConfig", # replaces 'django.contrib.admin' "core", "demo", "mailbox_manager", @@ -211,7 +217,6 @@ class Base(Configuration): "parler", "easy_thumbnails", # Django - "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.postgres", @@ -277,6 +282,10 @@ class Base(Configuration): "REDOC_DIST": "SIDECAR", } + # Django Admin + ADMIN_HEADER_BACKGROUND = values.Value(None) + ADMIN_HEADER_COLOR = values.Value(None) + # Mail EMAIL_BACKEND = values.Value("django.core.mail.backends.smtp.EmailBackend") EMAIL_HOST = values.Value(None) diff --git a/src/helm/env.d/production/values.desk.yaml.gotmpl b/src/helm/env.d/production/values.desk.yaml.gotmpl index e271aadd7..1b5e65700 100644 --- a/src/helm/env.d/production/values.desk.yaml.gotmpl +++ b/src/helm/env.d/production/values.desk.yaml.gotmpl @@ -8,6 +8,8 @@ backend: argocd.argoproj.io/hook: PostSync argocd.argoproj.io/hook-delete-policy: HookSucceeded envVars: + DJANGO_ADMIN_HEADER_BACKGROUND: "#dc3545" + DJANGO_ADMIN_HEADER_COLOR: "#ffffff" DJANGO_CSRF_TRUSTED_ORIGINS: https://regie.numerique.gouv.fr DJANGO_CONFIGURATION: Production DJANGO_ALLOWED_HOSTS: "*" diff --git a/src/helm/env.d/staging/values.desk.yaml.gotmpl b/src/helm/env.d/staging/values.desk.yaml.gotmpl index 95daa9eb7..42c0bdf29 100644 --- a/src/helm/env.d/staging/values.desk.yaml.gotmpl +++ b/src/helm/env.d/staging/values.desk.yaml.gotmpl @@ -8,6 +8,8 @@ backend: argocd.argoproj.io/hook: PreSync argocd.argoproj.io/hook-delete-policy: HookSucceeded envVars: + DJANGO_ADMIN_HEADER_BACKGROUND: "#0f5132" + DJANGO_ADMIN_HEADER_COLOR: "#ffffff" DJANGO_CSRF_TRUSTED_ORIGINS: http://desk-staging.beta.numerique.gouv.fr,https://desk-staging.beta.numerique.gouv.fr DJANGO_CONFIGURATION: Production DJANGO_ALLOWED_HOSTS: "*"