Skip to content

Commit d0e30f3

Browse files
authored
Merge pull request #728 from maykinmedia/feature/1647-banner
[#1647] Add configurable warning banner
2 parents d18beb2 + 8924029 commit d0e30f3

File tree

11 files changed

+146
-3
lines changed

11 files changed

+146
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load i18n icon_tags 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+
<span class="warning-header__icon">{% icon icon="error_outlined" icon_position="after" outlined=True %}</span>
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
@@ -109,6 +109,18 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
109109
)
110110
},
111111
),
112+
(
113+
_("Warning banner"),
114+
{
115+
"classes": ("collapse",),
116+
"fields": (
117+
"warning_banner_enabled",
118+
"warning_banner_text",
119+
"warning_banner_background_color",
120+
"warning_banner_font_color",
121+
),
122+
},
123+
),
112124
(
113125
_("Page texts"),
114126
{
@@ -276,6 +288,13 @@ def check_contrast_ratio(label1, color1, label2, color2, expected_ratio):
276288
obj.accent_font_color,
277289
ACCESSIBLE_CONTRAST_RATIO,
278290
)
291+
check_contrast_ratio(
292+
_("Warning banner background color"),
293+
obj.warning_banner_background_color,
294+
_("Warning banner font color"),
295+
obj.warning_banner_font_color,
296+
ACCESSIBLE_CONTRAST_RATIO,
297+
)
279298

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

src/open_inwoner/configurations/models.py

+20
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ class SiteConfiguration(SingletonModel):
5959
default=ColorTypeChoices.dark,
6060
help_text=_("The font color for when the background is the accent color"),
6161
)
62+
warning_banner_enabled = models.BooleanField(
63+
verbose_name=_("Show warning banner"),
64+
default=False,
65+
help_text=_("Whether the warning banner should be displayed"),
66+
)
67+
warning_banner_text = models.TextField(
68+
verbose_name=_("Warning banner text"),
69+
blank=True,
70+
help_text=_("Text will be displayed on the warning banner"),
71+
)
72+
warning_banner_background_color = ColorField(
73+
verbose_name=_("Warning banner background"),
74+
default="#FFDBAD",
75+
help_text=_("The background color for the warning banner"),
76+
)
77+
warning_banner_font_color = ColorField(
78+
verbose_name=_("Warning banner font"),
79+
default="#000000",
80+
help_text=_("The font color for the warning banner"),
81+
)
6282
logo = FilerImageField(
6383
verbose_name=_("Logo"),
6484
null=True,

src/open_inwoner/pdc/migrations/0037_category_highlighted.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Migration(migrations.Migration):
1515
name="highlighted",
1616
field=models.BooleanField(
1717
default=False,
18-
help_text="Wether the category should be highlighted or not",
18+
help_text="Whether the category should be highlighted or not",
1919
verbose_name="Highlighted",
2020
),
2121
),

src/open_inwoner/pdc/migrations/0038_auto_20220601_1435.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Generated by Django 3.2.13 on 2022-06-01 12:35
22

3+
import django.db.models.deletion
34
from django.conf import settings
45
from django.db import migrations, models
5-
import django.db.models.deletion
6+
67
import filer.fields.image
78

89

@@ -45,7 +46,7 @@ class Migration(migrations.Migration):
4546
name="highlighted",
4647
field=models.BooleanField(
4748
default=False,
48-
help_text="Wether the category should be highlighted or not.",
49+
help_text="Whether the category should be highlighted or not.",
4950
verbose_name="Highlighted",
5051
),
5152
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.warning-header {
2+
display: flex;
3+
box-sizing: border-box;
4+
padding: var(--spacing-large);
5+
6+
.warning-header__container {
7+
display: flex;
8+
align-items: center;
9+
padding: 0;
10+
margin: 0 auto;
11+
12+
@media (min-width: 768px) {
13+
max-width: 90%;
14+
}
15+
16+
.warning-header__icon,
17+
.warning-header__text {
18+
padding: var(--spacing-small);
19+
}
20+
.warning-header__icon {
21+
width: 20px;
22+
}
23+
}
24+
}

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';

src/open_inwoner/templates/master.html

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
</head>
4242

4343
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
44+
{% if warning_banner_enabled %}
45+
{% include "components/Header/WarningHeader.html" %}
46+
{% endif %}
47+
4448
{% cms_toolbar %}
4549

4650
{# render the cms menu and save for display in both mobile and desktop #}

src/open_inwoner/utils/context_processors.py

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def settings(request):
8888
[(k, getattr(django_settings, k, None)) for k in public_settings]
8989
),
9090
"hide_categories_from_anonymous_users": config.hide_categories_from_anonymous_users,
91+
"warning_banner_enabled": config.warning_banner_enabled,
92+
"warning_banner_text": config.warning_banner_text,
93+
"warning_banner_background_color": config.warning_banner_background_color,
94+
"warning_banner_font_color": config.warning_banner_font_color,
9195
}
9296

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