💄(admin) allow header color customization

This allows to use custom colors according to
environment.

FIXES #430
This commit is contained in:
Quentin BEY
2024-11-22 16:53:38 +01:00
committed by BEY Quentin
parent 9785ce295d
commit 0357caa75a
8 changed files with 51 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ and this project adheres to
### Added
- ✨(backend) add ServiceProvider #522
- 💄(admin) allow header color customization #552
### Fixed

View File

@@ -0,0 +1 @@
"""People custom admin site."""

View File

@@ -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"

View File

@@ -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,
}

View File

@@ -0,0 +1,10 @@
{% extends "admin/base_site.html" %}
{% block extrastyle %}{{ block.super }}
<style>
html[data-theme="light"], :root {
{% if ADMIN_HEADER_BACKGROUND %}--header-bg: {{ ADMIN_HEADER_BACKGROUND }};{% endif %}
{% if ADMIN_HEADER_COLOR %}--header-color: {{ ADMIN_HEADER_COLOR }};{% endif %}
}
</style>
{% endblock %}

View File

@@ -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)

View File

@@ -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: "*"

View File

@@ -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: "*"