From 4d770e16fde24b87170c1990324d17c1767b80cb Mon Sep 17 00:00:00 2001 From: Paul Schilling Date: Tue, 8 Aug 2023 12:21:08 +0200 Subject: [PATCH] [#1647] add configurable warning banner --- .../components/Header/WarningHeader.html | 15 ++++++ src/open_inwoner/configurations/admin.py | 19 +++++++ .../migrations/0047_auto_20230809_0833.py | 52 +++++++++++++++++++ src/open_inwoner/configurations/models.py | 20 +++++++ .../WarningHeader/WarningHeader.scss | 24 +++++++++ src/open_inwoner/scss/components/_index.scss | 1 + .../static/img/exclamation-encircled.svg | 4 ++ src/open_inwoner/templates/master.html | 4 ++ src/open_inwoner/utils/context_processors.py | 4 ++ src/open_inwoner/utils/templatetags/utils.py | 2 + 10 files changed, 145 insertions(+) create mode 100644 src/open_inwoner/components/templates/components/Header/WarningHeader.html create mode 100644 src/open_inwoner/configurations/migrations/0047_auto_20230809_0833.py create mode 100644 src/open_inwoner/scss/components/WarningHeader/WarningHeader.scss create mode 100644 src/open_inwoner/static/img/exclamation-encircled.svg diff --git a/src/open_inwoner/components/templates/components/Header/WarningHeader.html b/src/open_inwoner/components/templates/components/Header/WarningHeader.html new file mode 100644 index 0000000000..a3206f88cb --- /dev/null +++ b/src/open_inwoner/components/templates/components/Header/WarningHeader.html @@ -0,0 +1,15 @@ +{% load i18n icon_tags link_tags static %} + + + +
+
+ {% icon icon="error_outlined" icon_position="after" outlined=True %} + {{ warning_banner_text }} +
+
diff --git a/src/open_inwoner/configurations/admin.py b/src/open_inwoner/configurations/admin.py index 6aa1a0b3ca..90b7a10955 100644 --- a/src/open_inwoner/configurations/admin.py +++ b/src/open_inwoner/configurations/admin.py @@ -102,6 +102,18 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin): ) }, ), + ( + _("Warning banner"), + { + "classes": ("collapse",), + "fields": ( + "warning_banner_enabled", + "warning_banner_text", + "warning_banner_background_color", + "warning_banner_font_color", + ), + }, + ), ( _("Page texts"), { @@ -228,6 +240,13 @@ def check_contrast_ratio(label1, color1, label2, color2, expected_ratio): obj.accent_font_color, ACCESSIBLE_CONTRAST_RATIO, ) + check_contrast_ratio( + _("Warning banner background color"), + obj.warning_banner_background_color, + _("Warning banner font color"), + obj.warning_banner_font_color, + ACCESSIBLE_CONTRAST_RATIO, + ) def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) diff --git a/src/open_inwoner/configurations/migrations/0047_auto_20230809_0833.py b/src/open_inwoner/configurations/migrations/0047_auto_20230809_0833.py new file mode 100644 index 0000000000..791518e15c --- /dev/null +++ b/src/open_inwoner/configurations/migrations/0047_auto_20230809_0833.py @@ -0,0 +1,52 @@ +# Generated by Django 3.2.15 on 2023-08-09 06:33 + +import colorfield.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("configurations", "0046_siteconfiguration_cookie_consent"), + ] + + operations = [ + migrations.AddField( + model_name="siteconfiguration", + name="warning_banner_background_color", + field=colorfield.fields.ColorField( + default="#FFDBAD", + help_text="The background color for the warning banner", + max_length=18, + verbose_name="Warning banner background", + ), + ), + migrations.AddField( + model_name="siteconfiguration", + name="warning_banner_enabled", + field=models.BooleanField( + default=False, + help_text="Wether the warning banner should be displayed", + verbose_name="Show warning banner", + ), + ), + migrations.AddField( + model_name="siteconfiguration", + name="warning_banner_font_color", + field=colorfield.fields.ColorField( + default="#000000", + help_text="The font color for the warning banner", + max_length=18, + verbose_name="Warning banner font", + ), + ), + migrations.AddField( + model_name="siteconfiguration", + name="warning_banner_text", + field=models.TextField( + blank=True, + help_text="Text will be displayed on the warning banner", + verbose_name="Warning banner text", + ), + ), + ] diff --git a/src/open_inwoner/configurations/models.py b/src/open_inwoner/configurations/models.py index 8e44aef0e1..020df41a82 100644 --- a/src/open_inwoner/configurations/models.py +++ b/src/open_inwoner/configurations/models.py @@ -57,6 +57,26 @@ class SiteConfiguration(SingletonModel): default=ColorTypeChoices.dark, help_text=_("The font color for when the background is the accent color"), ) + warning_banner_enabled = models.BooleanField( + verbose_name=_("Show warning banner"), + default=False, + help_text=_("Wether the warning banner should be displayed"), + ) + warning_banner_text = models.TextField( + verbose_name=_("Warning banner text"), + blank=True, + help_text=_("Text will be displayed on the warning banner"), + ) + warning_banner_background_color = ColorField( + verbose_name=_("Warning banner background"), + default="#FFDBAD", + help_text=_("The background color for the warning banner"), + ) + warning_banner_font_color = ColorField( + verbose_name=_("Warning banner font"), + default="#000000", + help_text=_("The font color for the warning banner"), + ) logo = FilerImageField( verbose_name=_("Logo"), null=True, diff --git a/src/open_inwoner/scss/components/WarningHeader/WarningHeader.scss b/src/open_inwoner/scss/components/WarningHeader/WarningHeader.scss new file mode 100644 index 0000000000..b173445a7d --- /dev/null +++ b/src/open_inwoner/scss/components/WarningHeader/WarningHeader.scss @@ -0,0 +1,24 @@ +.warning-header { + display: flex; + box-sizing: border-box; + padding: var(--spacing-large); + + .warning-header__container { + display: flex; + align-items: center; + padding: 0; + margin: 0 auto; + + @media (min-width: 768px) { + max-width: 90%; + } + + .warning-header__icon, + .warning-header__text { + padding: var(--spacing-small); + } + .warning-header__icon { + width: 20px; + } + } +} diff --git a/src/open_inwoner/scss/components/_index.scss b/src/open_inwoner/scss/components/_index.scss index 26476a8a66..050955c39b 100644 --- a/src/open_inwoner/scss/components/_index.scss +++ b/src/open_inwoner/scss/components/_index.scss @@ -97,3 +97,4 @@ @import './Emoji/Emoji.scss'; @import './Profile/personal-information'; @import './Profile/edit.scss'; +@import './WarningHeader/WarningHeader.scss'; diff --git a/src/open_inwoner/static/img/exclamation-encircled.svg b/src/open_inwoner/static/img/exclamation-encircled.svg new file mode 100644 index 0000000000..e44f45398f --- /dev/null +++ b/src/open_inwoner/static/img/exclamation-encircled.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/open_inwoner/templates/master.html b/src/open_inwoner/templates/master.html index 511a2acd19..8971fbf0b3 100644 --- a/src/open_inwoner/templates/master.html +++ b/src/open_inwoner/templates/master.html @@ -37,6 +37,10 @@ + {% if warning_banner_enabled %} + {% include "components/Header/WarningHeader.html" %} + {% endif %} + {% cms_toolbar %} {% header categories=menu_categories request=request breadcrumbs=breadcrumbs search_form=search_form has_general_faq_questions=has_general_faq_questions cms_apps=cms_apps %} diff --git a/src/open_inwoner/utils/context_processors.py b/src/open_inwoner/utils/context_processors.py index 21e30374a7..a90a511b25 100644 --- a/src/open_inwoner/utils/context_processors.py +++ b/src/open_inwoner/utils/context_processors.py @@ -86,6 +86,10 @@ def settings(request): "settings": dict( [(k, getattr(django_settings, k, None)) for k in public_settings] ), + "warning_banner_enabled": config.warning_banner_enabled, + "warning_banner_text": config.warning_banner_text, + "warning_banner_background_color": config.warning_banner_background_color, + "warning_banner_font_color": config.warning_banner_font_color, } if hasattr(django_settings, "SENTRY_CONFIG"): diff --git a/src/open_inwoner/utils/templatetags/utils.py b/src/open_inwoner/utils/templatetags/utils.py index 1154b42ace..832d8ab7a9 100644 --- a/src/open_inwoner/utils/templatetags/utils.py +++ b/src/open_inwoner/utils/templatetags/utils.py @@ -5,6 +5,8 @@ from humanfriendly import format_size +from open_inwoner.configurations.models import SiteConfiguration + register = template.Library()