From 363a425bf073de11ab03a72f42718e615b3a4094 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 22 Oct 2025 10:27:26 +0100 Subject: [PATCH 1/7] Adds introduction field for blog index --- .../migrations/0030_adds_introduction_field.py | 17 +++++++++++++++++ tbx/blog/models.py | 9 ++++++++- .../molecules/title-filters/title-filters.html | 6 ++++++ .../patterns/pages/blog/blog_listing.html | 3 ++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tbx/blog/migrations/0030_adds_introduction_field.py diff --git a/tbx/blog/migrations/0030_adds_introduction_field.py b/tbx/blog/migrations/0030_adds_introduction_field.py new file mode 100644 index 000000000..aa622e02d --- /dev/null +++ b/tbx/blog/migrations/0030_adds_introduction_field.py @@ -0,0 +1,17 @@ +# Generated by Django 5.2.5 on 2025-10-22 08:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("blog", "0029_relatedblogpage"), + ] + + operations = [ + migrations.AlterField( + model_name="blogindexpage", + name="introduction", + field=models.TextField(blank=True), + ), + ] diff --git a/tbx/blog/models.py b/tbx/blog/models.py index ae127df5e..039c135c9 100644 --- a/tbx/blog/models.py +++ b/tbx/blog/models.py @@ -37,9 +37,16 @@ class BlogIndexPage(BasePage): template = "patterns/pages/blog/blog_listing.html" - subpage_types = ["BlogPage"] + introduction = models.TextField( + blank=True, + ) + + content_panels = BasePage.content_panels + [ + FieldPanel("introduction"), + ] + @cached_property def taxonomy_slugs(self): services = Service.objects.values_list("slug", flat=True) diff --git a/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html b/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html index 29f82ddec..4d65d50c5 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html +++ b/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html @@ -5,6 +5,12 @@

{{ item.title }}

+ {% if introduction %} +
+

{{ introduction|linebreaksbr }}

+
+ {% endif %} + {% if tags and not hide_tags %}
diff --git a/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html b/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html index b82a2fabd..67f9ccc7d 100644 --- a/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html +++ b/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html @@ -10,7 +10,8 @@ {% block content %}
- {% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags %} + + {% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags introduction=page.introduction %}
    {% for post in blog_posts %} From 4756666230765450a74b5689e25a769ff7565730 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 22 Oct 2025 10:37:41 +0100 Subject: [PATCH 2/7] Add new styled page links blocks for blog index --- .../0031_blogindexpage_page_links.py | 21 ++++++++++ tbx/blog/models.py | 12 +++++- tbx/core/blocks.py | 27 +++++++++++++ .../blocks/styled_page_link_block.html | 9 +++++ .../blocks/styled_page_link_block.yaml | 12 ++++++ .../title-filters/title-filters.html | 8 ++++ .../patterns/pages/blog/blog_listing.html | 2 +- .../sass/components/_four-photo-collage.scss | 7 ++-- tbx/static_src/sass/components/_grid.scss | 8 +++- .../sass/components/_styled-page-links.scss | 40 +++++++++++++++++++ tbx/static_src/sass/main.scss | 1 + 11 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 tbx/blog/migrations/0031_blogindexpage_page_links.py create mode 100644 tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.html create mode 100644 tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.yaml create mode 100644 tbx/static_src/sass/components/_styled-page-links.scss diff --git a/tbx/blog/migrations/0031_blogindexpage_page_links.py b/tbx/blog/migrations/0031_blogindexpage_page_links.py new file mode 100644 index 000000000..5a5e34b34 --- /dev/null +++ b/tbx/blog/migrations/0031_blogindexpage_page_links.py @@ -0,0 +1,21 @@ +# Generated by Django 5.2.5 on 2025-10-22 09:34 + +from django.db import migrations + +import tbx.core.utils.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("blog", "0030_adds_introduction_field"), + ] + + operations = [ + migrations.AddField( + model_name="blogindexpage", + name="page_links", + field=tbx.core.utils.fields.StreamField( + blank=True, block_lookup={}, help_text="Add up to 3 styled page links." + ), + ), + ] diff --git a/tbx/blog/models.py b/tbx/blog/models.py index 039c135c9..dc69b859a 100644 --- a/tbx/blog/models.py +++ b/tbx/blog/models.py @@ -23,7 +23,7 @@ from bs4 import BeautifulSoup -from tbx.core.blocks import StoryBlock +from tbx.core.blocks import StoryBlock, StyledPageLinkBlock from tbx.core.models import BasePage from tbx.core.utils.fields import StreamField from tbx.core.utils.models import ( @@ -43,8 +43,18 @@ class BlogIndexPage(BasePage): blank=True, ) + page_links = StreamField( + [ + ("styled_page_link", StyledPageLinkBlock()), + ], + blank=True, + max_num=3, + help_text="Add up to 3 styled page links.", + ) + content_panels = BasePage.content_panels + [ FieldPanel("introduction"), + FieldPanel("page_links"), ] @cached_property diff --git a/tbx/core/blocks.py b/tbx/core/blocks.py index 22cbca4dc..39f74480a 100644 --- a/tbx/core/blocks.py +++ b/tbx/core/blocks.py @@ -48,6 +48,33 @@ def text(self): return page.title +class StyledPageLinkBlock(blocks.StructBlock): + """ + A styled page link block with optional title and style choices. + """ + + class StyleChoice(models.TextChoices): + CHARITY = "charity", "Charity" + PUBLIC = "public", "Public" + WAGTAIL = "wagtail", "Wagtail" + + page = blocks.PageChooserBlock() + title = blocks.CharBlock( + required=False, + help_text="Optional custom title. If not provided, the page title will be used.", + ) + style = blocks.ChoiceBlock( + choices=StyleChoice.choices, + default=StyleChoice.CHARITY, + help_text="Choose the visual style for this link.", + ) + + class Meta: + icon = "link" + label = "Styled Page Link" + template = "patterns/molecules/streamfield/blocks/styled_page_link_block.html" + + class InternalLinkBlock(blocks.StructBlock): page = blocks.PageChooserBlock() link_text = blocks.CharBlock(required=False) diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.html b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.html new file mode 100644 index 000000000..83e6039fa --- /dev/null +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.html @@ -0,0 +1,9 @@ +{% load wagtailcore_tags %} + + + {% if value.title %} + {{ value.title }} + {% else %} + {{ value.page.title }} + {% endif %} + diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.yaml b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.yaml new file mode 100644 index 000000000..6f3ce47e9 --- /dev/null +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/styled_page_link_block.yaml @@ -0,0 +1,12 @@ +context: + value: + page: + title: Charity + url: '#' + title: Charity + style: charity + +tags: + pageurl: + value.page: + raw: '#' diff --git a/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html b/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html index 4d65d50c5..99b26e45a 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html +++ b/tbx/project_styleguide/templates/patterns/molecules/title-filters/title-filters.html @@ -11,6 +11,14 @@

    {{ item.title }}

{% endif %} + {% if page_links %} + + {% endif %} + {% if tags and not hide_tags %}
diff --git a/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html b/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html index 67f9ccc7d..3f9ca4494 100644 --- a/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html +++ b/tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html @@ -11,7 +11,7 @@ {% block content %}
- {% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags introduction=page.introduction %} + {% include "patterns/molecules/title-filters/title-filters.html" with item=page tags=tags introduction=page.introduction page_links=page.page_links %}