Skip to content

Commit 9712097

Browse files
committed
[#1647] add configurable warning banner
1 parent 4e2861a commit 9712097

File tree

10 files changed

+141
-0
lines changed

10 files changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load i18n link_tags static %}
2+
3+
<style nonce="{{ request.csp_nonce }}">
4+
.warning-header {
5+
background-color: {{ warning_banner_background_color }};
6+
color: {{ warning_banner_font_color }};
7+
}
8+
</style>
9+
10+
<div class="warning-header">
11+
<div class="warning-header__container">
12+
<img class="warning-header__icon" alt="Vignet" src="{% static 'img/exclamation-encircled.svg' %}"/>
13+
<span class="warning-header__text">{{ warning_banner_text }}</span>
14+
</div>
15+
</div>

src/open_inwoner/configurations/admin.py

+19
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
102102
)
103103
},
104104
),
105+
(
106+
_("Warning banner"),
107+
{
108+
"classes": ("collapse",),
109+
"fields": (
110+
"warning_banner_enabled",
111+
"warning_banner_text",
112+
"warning_banner_background_color",
113+
"warning_banner_font_color",
114+
),
115+
},
116+
),
105117
(
106118
_("Page texts"),
107119
{
@@ -228,6 +240,13 @@ def check_contrast_ratio(label1, color1, label2, color2, expected_ratio):
228240
obj.accent_font_color,
229241
ACCESSIBLE_CONTRAST_RATIO,
230242
)
243+
check_contrast_ratio(
244+
_("Warning banner background color"),
245+
obj.warning_banner_background_color,
246+
_("Warning banner font color"),
247+
obj.warning_banner_font_color,
248+
ACCESSIBLE_CONTRAST_RATIO,
249+
)
231250

232251
def save_model(self, request, obj, form, change):
233252
super().save_model(request, obj, form, change)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Generated by Django 3.2.15 on 2023-08-09 06:33
2+
3+
import colorfield.fields
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("configurations", "0046_siteconfiguration_cookie_consent"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="siteconfiguration",
16+
name="warning_banner_background_color",
17+
field=colorfield.fields.ColorField(
18+
default="#FFDBAD",
19+
help_text="The background color for the warning banner",
20+
max_length=18,
21+
verbose_name="Warning banner background",
22+
),
23+
),
24+
migrations.AddField(
25+
model_name="siteconfiguration",
26+
name="warning_banner_enabled",
27+
field=models.BooleanField(
28+
default=False,
29+
help_text="Wether the warning banner should be displayed",
30+
verbose_name="Show warning banner",
31+
),
32+
),
33+
migrations.AddField(
34+
model_name="siteconfiguration",
35+
name="warning_banner_font_color",
36+
field=colorfield.fields.ColorField(
37+
default="#000000",
38+
help_text="The font color for the warning banner",
39+
max_length=18,
40+
verbose_name="Warning banner font",
41+
),
42+
),
43+
migrations.AddField(
44+
model_name="siteconfiguration",
45+
name="warning_banner_text",
46+
field=models.TextField(
47+
blank=True,
48+
help_text="Text will be displayed on the warning banner",
49+
verbose_name="Warning banner text",
50+
),
51+
),
52+
]

src/open_inwoner/configurations/models.py

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ class SiteConfiguration(SingletonModel):
5757
default=ColorTypeChoices.dark,
5858
help_text=_("The font color for when the background is the accent color"),
5959
)
60+
warning_banner_enabled = models.BooleanField(
61+
verbose_name=_("Show warning banner"),
62+
default=False,
63+
help_text=_("Wether the warning banner should be displayed"),
64+
)
65+
warning_banner_text = models.TextField(
66+
verbose_name=_("Warning banner text"),
67+
blank=True,
68+
help_text=_("Text will be displayed on the warning banner"),
69+
)
70+
warning_banner_background_color = ColorField(
71+
verbose_name=_("Warning banner background"),
72+
default="#FFDBAD",
73+
help_text=_("The background color for the warning banner"),
74+
)
75+
warning_banner_font_color = ColorField(
76+
verbose_name=_("Warning banner font"),
77+
default="#000000",
78+
help_text=_("The font color for the warning banner"),
79+
)
6080
logo = FilerImageField(
6181
verbose_name=_("Logo"),
6282
null=True,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.warning-header {
2+
display: flex;
3+
box-sizing: border-box;
4+
padding: 1rem;
5+
6+
.warning-header__container {
7+
display: flex;
8+
align-items: center;
9+
padding: 0 4rem;
10+
margin: 0 auto;
11+
12+
.warning-header__icon,
13+
.warning-header__text {
14+
padding: 0.25rem;
15+
}
16+
.warning-header__icon {
17+
width: 20px;
18+
}
19+
}
20+
}

src/open_inwoner/scss/components/_index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@
9797
@import './Emoji/Emoji.scss';
9898
@import './Profile/personal-information';
9999
@import './Profile/edit.scss';
100+
@import './WarningHeader/WarningHeader.scss';
Loading

src/open_inwoner/templates/master.html

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
</head>
3838

3939
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
40+
{% if warning_banner_enabled %}
41+
{% include "components/Header/WarningHeader.html" %}
42+
{% endif %}
43+
4044
{% cms_toolbar %}
4145
{% header categories=menu_categories request=request breadcrumbs=breadcrumbs search_form=search_form has_general_faq_questions=has_general_faq_questions cms_apps=cms_apps %}
4246

src/open_inwoner/utils/context_processors.py

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def settings(request):
8686
"settings": dict(
8787
[(k, getattr(django_settings, k, None)) for k in public_settings]
8888
),
89+
"warning_banner_enabled": config.warning_banner_enabled,
90+
"warning_banner_text": config.warning_banner_text,
91+
"warning_banner_background_color": config.warning_banner_background_color,
92+
"warning_banner_font_color": config.warning_banner_font_color,
8993
}
9094

9195
if hasattr(django_settings, "SENTRY_CONFIG"):

src/open_inwoner/utils/templatetags/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from humanfriendly import format_size
77

8+
from open_inwoner.configurations.models import SiteConfiguration
9+
810
register = template.Library()
911

1012

0 commit comments

Comments
 (0)