Skip to content

Commit 1632078

Browse files
authored
Add settings for the cookie page and the digital emissions page (#287)
* Add settings for the cookie page and the digital emissions page
1 parent 7930c87 commit 1632078

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

tbx/core/context_processors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
from django.conf import settings
22

3+
from tbx.core.models import ImportantPageSettings
4+
35

46
def global_vars(request):
57
return {
68
"GOOGLE_TAG_MANAGER_ID": getattr(settings, "GOOGLE_TAG_MANAGER_ID", None),
79
"SEO_NOINDEX": settings.SEO_NOINDEX,
10+
"COOKIE_POLICY_PAGE": ImportantPageSettings.for_request(
11+
request
12+
).cookie_policy_page,
13+
"CARBON_EMISSIONS_PAGE": ImportantPageSettings.for_request(
14+
request
15+
).carbon_emissions_page,
816
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Generated by Django 4.2.11 on 2024-07-22 13:39
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("wagtailcore", "0091_remove_revision_submitted_for_moderation"),
11+
("torchbox", "0034_add_earth_colour_theme"),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="ImportantPageSettings",
17+
fields=[
18+
(
19+
"id",
20+
models.AutoField(
21+
auto_created=True,
22+
primary_key=True,
23+
serialize=False,
24+
verbose_name="ID",
25+
),
26+
),
27+
(
28+
"carbon_emissions_page",
29+
models.ForeignKey(
30+
blank=True,
31+
null=True,
32+
on_delete=django.db.models.deletion.SET_NULL,
33+
related_name="+",
34+
to="wagtailcore.page",
35+
),
36+
),
37+
(
38+
"cookie_policy_page",
39+
models.ForeignKey(
40+
blank=True,
41+
null=True,
42+
on_delete=django.db.models.deletion.SET_NULL,
43+
related_name="+",
44+
to="wagtailcore.page",
45+
),
46+
),
47+
(
48+
"site",
49+
models.OneToOneField(
50+
editable=False,
51+
on_delete=django.db.models.deletion.CASCADE,
52+
to="wagtailcore.site",
53+
),
54+
),
55+
],
56+
options={
57+
"abstract": False,
58+
},
59+
),
60+
]

tbx/core/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,27 @@ class MainMenu(BaseSiteSetting):
247247
panels = [
248248
FieldPanel("menu"),
249249
]
250+
251+
252+
@register_setting
253+
class ImportantPageSettings(BaseSiteSetting):
254+
cookie_policy_page = models.ForeignKey(
255+
"wagtailcore.Page",
256+
blank=True,
257+
null=True,
258+
on_delete=models.SET_NULL,
259+
related_name="+",
260+
)
261+
262+
carbon_emissions_page = models.ForeignKey(
263+
"wagtailcore.Page",
264+
blank=True,
265+
null=True,
266+
on_delete=models.SET_NULL,
267+
related_name="+",
268+
)
269+
270+
panels = [
271+
FieldPanel("cookie_policy_page"),
272+
FieldPanel("carbon_emissions_page"),
273+
]
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
{% load wagtailcore_tags %}
2+
13
<div class="grid footer__carbon-impact-container" data-page-carbon>
24
<div class="grid__carbon-impact">
35
<div class="footer__carbon-impact">
46
<p class="footer__carbon-impact-text">Loading the site homepage emits just <span>0.07g of CO2</span> per view.</p>
5-
<p class="footer__carbon-impact-text"><a href="/about/digital-emissions/" class="footer__carbon-impact-link">Find out more about our carbon impact</a></p>
7+
{% if CARBON_EMISSIONS_PAGE %}
8+
<p class="footer__carbon-impact-text">
9+
<a href="{% pageurl CARBON_EMISSIONS_PAGE %}" class="footer__carbon-impact-link">Find out more about our carbon impact</a>
10+
</p>
11+
{% endif %}
612
</div>
713
</div>
814
</div>

tbx/project_styleguide/templates/patterns/molecules/cookie-message/cookie-message.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
{% load wagtailcore_tags %}
12
<div data-cookie-message class="cookie-message {{ classes }}">
23
<div class="cookie-message__container grid">
34
<div class="cookie-message__message grid__cookie-message">
4-
<p>We use cookies to measure how you use the website. We want our site to be easy for you to use; understanding how you interact with it helps us know that. <a aria-label="Find out more about how we use cookies" href="/cookies/" class="cookie-message__link">Find out more</a>.</p>
5+
<p>We use cookies to measure how you use the website. We want our site to be easy for you to use; understanding how you interact with it helps us know that. {% if COOKIE_POLICY_PAGE %}<a aria-label="Find out more about how we use cookies" href="{% pageurl COOKIE_POLICY_PAGE %}" class="cookie-message__link">Find out more</a>{% endif %}.</p>
56
</div>
67
<div class="cookie-message__action grid__cookie-message">
78
{# ids are needed by GTM #}

0 commit comments

Comments
 (0)