From 63898aaeba5751a3f99a359f80f6a89eeff1c07a Mon Sep 17 00:00:00 2001 From: Amanda Lim-Cabuloy Date: Fri, 6 Dec 2024 18:38:21 +0800 Subject: [PATCH 1/4] Add division signpost block (BE) --- tbx/core/blocks.py | 46 +++++++++++++++++++ .../blocks/division_signpost_block.html | 20 ++++++++ tbx/settings/base.py | 24 +++++----- 3 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html diff --git a/tbx/core/blocks.py b/tbx/core/blocks.py index 96bb0e65..cea2ec1c 100644 --- a/tbx/core/blocks.py +++ b/tbx/core/blocks.py @@ -3,6 +3,7 @@ from datetime import datetime from typing import Optional +from django.conf import settings from django.core.exceptions import ValidationError from django.db import models from django.forms.utils import ErrorList @@ -297,6 +298,50 @@ class IconChoice(models.TextChoices): WAGTAIL = "wagtail", "wagtail icon" +class DivisionSignpostCardValue(blocks.StructValue): + def get_heading(self): + if override := self.get("heading"): + return override + return self["page"].title + + +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 + ) + heading = blocks.CharBlock(required=False) + description = blocks.RichTextBlock(features=settings.NO_HEADING_RICH_TEXT_FEATURES) + image = ImageChooserBlock() + link_text = blocks.CharBlock() + page = blocks.PageChooserBlock() + + class Meta: + icon = "breadcrumb-expand" + value_class = DivisionSignpostCardValue + + +class DivisionSignpostBlock(blocks.StructBlock): + title = blocks.CharBlock(max_length=255, required=False) + intro = blocks.RichTextBlock( + features=settings.NO_HEADING_RICH_TEXT_FEATURES, required=False + ) + cards = blocks.ListBlock( + DivisionSignpostCardBlock(), + max_num=3, + min_num=1, + ) + + class Meta: + group = "Custom" + icon = "thumbtack" + template = "patterns/molecules/streamfield/blocks/division_signpost_block.html" + + class HomepageShowcaseBlock(blocks.StructBlock): """ This block is similar to the ShowcaseBlock, but is rendered larger @@ -943,6 +988,7 @@ class StandardPageStoryBlock(StoryBlock): class HomePageStoryBlock(blocks.StreamBlock): + division_signpost = DivisionSignpostBlock() showcase = ShowcaseBlock(label="Standard showcase") homepage_showcase = HomepageShowcaseBlock(label="Large showcase with icons") featured_case_study = FeaturedCaseStudyBlock() diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html new file mode 100644 index 00000000..0faba298 --- /dev/null +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html @@ -0,0 +1,20 @@ +{% load wagtailcore_tags wagtailimages_tags %} +
+ {# Section heading #} +

{{ value.title }}

+ + {# Section intro #} +
{{ value.intro|richtext }}
+ + {# Signposting cards #} + +
diff --git a/tbx/settings/base.py b/tbx/settings/base.py index 9a1d5ae0..c7da504c 100644 --- a/tbx/settings/base.py +++ b/tbx/settings/base.py @@ -634,21 +634,23 @@ # Rich text settings +DEFAULT_RICH_TEXT_FEATURES = [ + "h2", + "h3", + "h4", + "bold", + "italic", + "ul", + "ol", + "link", + "document-link", +] +NO_HEADING_RICH_TEXT_FEATURES = ["bold", "italic", "ul", "ol", "link", "document-link"] WAGTAILADMIN_RICH_TEXT_EDITORS = { "default": { "WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea", "OPTIONS": { - "features": [ - "h2", - "h3", - "h4", - "bold", - "italic", - "ul", - "ol", - "link", - "document-link", - ] + "features": DEFAULT_RICH_TEXT_FEATURES, }, }, } From 14652535cac9e1f02d38aa07d4945fbe7fd6bf1a Mon Sep 17 00:00:00 2001 From: Amanda Lim-Cabuloy Date: Fri, 6 Dec 2024 19:52:54 +0800 Subject: [PATCH 2/4] Use firstof instead of a StructValue --- tbx/core/blocks.py | 8 -------- .../streamfield/blocks/division_signpost_block.html | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/tbx/core/blocks.py b/tbx/core/blocks.py index cea2ec1c..2061c382 100644 --- a/tbx/core/blocks.py +++ b/tbx/core/blocks.py @@ -298,13 +298,6 @@ class IconChoice(models.TextChoices): WAGTAIL = "wagtail", "wagtail icon" -class DivisionSignpostCardValue(blocks.StructValue): - def get_heading(self): - if override := self.get("heading"): - return override - return self["page"].title - - class DivisionSignpostCardBlock(blocks.StructBlock): class ColourTheme(models.TextChoices): CORAL = "theme-coral", "Coral" @@ -322,7 +315,6 @@ class ColourTheme(models.TextChoices): class Meta: icon = "breadcrumb-expand" - value_class = DivisionSignpostCardValue class DivisionSignpostBlock(blocks.StructBlock): diff --git a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html index 0faba298..31bb0517 100644 --- a/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html +++ b/tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/division_signpost_block.html @@ -10,7 +10,7 @@

{{ value.title }}