diff --git a/tbx/blog/migrations/0030_blogindexpage_introduction_and_page_links.py b/tbx/blog/migrations/0030_blogindexpage_introduction_and_page_links.py new file mode 100644 index 000000000..0ebc84c92 --- /dev/null +++ b/tbx/blog/migrations/0030_blogindexpage_introduction_and_page_links.py @@ -0,0 +1,26 @@ +# Generated by Django 5.2.5 on 2025-10-22 09:34 + +from django.db import migrations, models + +import tbx.core.utils.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("blog", "0029_relatedblogpage"), + ] + + operations = [ + migrations.AddField( + model_name="blogindexpage", + name="introduction", + field=models.TextField(blank=True), + ), + 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 ae127df5e..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 ( @@ -37,9 +37,26 @@ class BlogIndexPage(BasePage): template = "patterns/pages/blog/blog_listing.html" - subpage_types = ["BlogPage"] + introduction = models.TextField( + 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 def taxonomy_slugs(self): services = Service.objects.values_list("slug", flat=True) diff --git a/tbx/core/blocks.py b/tbx/core/blocks.py index 22cbca4dc..e2d92f29b 100644 --- a/tbx/core/blocks.py +++ b/tbx/core/blocks.py @@ -32,6 +32,12 @@ logger = logging.getLogger(__name__) +class ColourTheme(models.TextChoices): + CORAL = "theme-coral", "Coral" + NEBULINE = "theme-nebuline", "Nebuline" + LAGOON = "theme-lagoon", "Lagoon" + + class LinkStructValue(blocks.StructValue): @cached_property def url(self): @@ -48,6 +54,28 @@ def text(self): return page.title +class StyledPageLinkBlock(blocks.StructBlock): + """ + A styled page link block with optional title and style choices. + """ + + 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=ColourTheme.choices, + default=ColourTheme.CORAL, + 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) @@ -553,11 +581,6 @@ class IconChoice(models.TextChoices): class DivisionSignpostCardBlock(blocks.StructBlock): - class ColourTheme(models.TextChoices): - CORAL = "theme-coral", "Coral" - NEBULINE = "theme-nebuline", "Nebuline" - LAGOON = "theme-lagoon", "Lagoon" - card_colour = blocks.ChoiceBlock( choices=ColourTheme.choices, default=ColourTheme.CORAL, max_length=20 ) 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..c541e4136 --- /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 29f82ddec..cc1fb3260 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 @@ -1,11 +1,29 @@ {% load wagtailcore_tags %} -