Skip to content

Commit

Permalink
Add settings for the cookie page and the digital emissions page (#287)
Browse files Browse the repository at this point in the history
* Add settings for the cookie page and the digital emissions page
  • Loading branch information
helenb authored Jul 25, 2024
1 parent 7930c87 commit 1632078
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tbx/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from django.conf import settings

from tbx.core.models import ImportantPageSettings


def global_vars(request):
return {
"GOOGLE_TAG_MANAGER_ID": getattr(settings, "GOOGLE_TAG_MANAGER_ID", None),
"SEO_NOINDEX": settings.SEO_NOINDEX,
"COOKIE_POLICY_PAGE": ImportantPageSettings.for_request(
request
).cookie_policy_page,
"CARBON_EMISSIONS_PAGE": ImportantPageSettings.for_request(
request
).carbon_emissions_page,
}
60 changes: 60 additions & 0 deletions tbx/core/migrations/0035_add_important_page_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 4.2.11 on 2024-07-22 13:39

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("wagtailcore", "0091_remove_revision_submitted_for_moderation"),
("torchbox", "0034_add_earth_colour_theme"),
]

operations = [
migrations.CreateModel(
name="ImportantPageSettings",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"carbon_emissions_page",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailcore.page",
),
),
(
"cookie_policy_page",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailcore.page",
),
),
(
"site",
models.OneToOneField(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
to="wagtailcore.site",
),
),
],
options={
"abstract": False,
},
),
]
24 changes: 24 additions & 0 deletions tbx/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,27 @@ class MainMenu(BaseSiteSetting):
panels = [
FieldPanel("menu"),
]


@register_setting
class ImportantPageSettings(BaseSiteSetting):
cookie_policy_page = models.ForeignKey(
"wagtailcore.Page",
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="+",
)

carbon_emissions_page = models.ForeignKey(
"wagtailcore.Page",
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="+",
)

panels = [
FieldPanel("cookie_policy_page"),
FieldPanel("carbon_emissions_page"),
]
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{% load wagtailcore_tags %}

<div class="grid footer__carbon-impact-container" data-page-carbon>
<div class="grid__carbon-impact">
<div class="footer__carbon-impact">
<p class="footer__carbon-impact-text">Loading the site homepage emits just <span>0.07g of CO2</span> per view.</p>
<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>
{% if CARBON_EMISSIONS_PAGE %}
<p class="footer__carbon-impact-text">
<a href="{% pageurl CARBON_EMISSIONS_PAGE %}" class="footer__carbon-impact-link">Find out more about our carbon impact</a>
</p>
{% endif %}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% load wagtailcore_tags %}
<div data-cookie-message class="cookie-message {{ classes }}">
<div class="cookie-message__container grid">
<div class="cookie-message__message grid__cookie-message">
<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>
<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>
</div>
<div class="cookie-message__action grid__cookie-message">
{# ids are needed by GTM #}
Expand Down

0 comments on commit 1632078

Please sign in to comment.