Skip to content

Commit 8bb2598

Browse files
authored
TWE-2 - BE - Add division signpost block (#314)
* Add division signpost block (BE) * Use firstof instead of a StructValue
1 parent 4400045 commit 8bb2598

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

tbx/core/blocks.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44
from typing import Optional
55

6+
from django.conf import settings
67
from django.core.exceptions import ValidationError
78
from django.db import models
89
from django.forms.utils import ErrorList
@@ -297,6 +298,44 @@ class IconChoice(models.TextChoices):
297298
WAGTAIL = "wagtail", "wagtail icon"
298299

299300

301+
class DivisionSignpostCardBlock(blocks.StructBlock):
302+
class ColourTheme(models.TextChoices):
303+
CORAL = "theme-coral", "Coral"
304+
NEBULINE = "theme-nebuline", "Nebuline"
305+
LAGOON = "theme-lagoon", "Lagoon"
306+
307+
card_colour = blocks.ChoiceBlock(
308+
choices=ColourTheme.choices, default=ColourTheme.CORAL, max_length=20
309+
)
310+
heading = blocks.CharBlock(required=False)
311+
description = blocks.RichTextBlock(features=settings.NO_HEADING_RICH_TEXT_FEATURES)
312+
image = ImageChooserBlock()
313+
link_text = blocks.CharBlock(
314+
help_text=("This should be descriptive for accessibility."),
315+
)
316+
page = blocks.PageChooserBlock()
317+
318+
class Meta:
319+
icon = "breadcrumb-expand"
320+
321+
322+
class DivisionSignpostBlock(blocks.StructBlock):
323+
title = blocks.CharBlock(max_length=255, required=False)
324+
intro = blocks.RichTextBlock(
325+
features=settings.NO_HEADING_RICH_TEXT_FEATURES, required=False
326+
)
327+
cards = blocks.ListBlock(
328+
DivisionSignpostCardBlock(),
329+
max_num=3,
330+
min_num=3,
331+
)
332+
333+
class Meta:
334+
group = "Custom"
335+
icon = "thumbtack"
336+
template = "patterns/molecules/streamfield/blocks/division_signpost_block.html"
337+
338+
300339
class HomepageShowcaseBlock(blocks.StructBlock):
301340
"""
302341
This block is similar to the ShowcaseBlock, but is rendered larger
@@ -943,6 +982,7 @@ class StandardPageStoryBlock(StoryBlock):
943982

944983

945984
class HomePageStoryBlock(blocks.StreamBlock):
985+
division_signpost = DivisionSignpostBlock()
946986
showcase = ShowcaseBlock(label="Standard showcase")
947987
homepage_showcase = HomepageShowcaseBlock(label="Large showcase with icons")
948988
featured_case_study = FeaturedCaseStudyBlock()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% load wagtailcore_tags wagtailimages_tags %}
2+
<div>
3+
{# Section heading #}
4+
<h2>{{ value.title }}</h2>
5+
6+
{# Section intro #}
7+
<div>{{ value.intro|richtext }}</div>
8+
9+
{# Signposting cards #}
10+
<ul>
11+
{% for card in value.cards %}
12+
<li class="{{ card.card_colour }}">
13+
{% firstof card.heading card.page.title %}
14+
{{ card.description|richtext }}
15+
{% image card.image fill-100x100 %}
16+
<a href="{% pageurl card.page %}">{{ card.link_text }}</a>
17+
</li>
18+
{% endfor %}
19+
</ul>
20+
</div>

tbx/settings/base.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -634,21 +634,23 @@
634634

635635

636636
# Rich text settings
637+
DEFAULT_RICH_TEXT_FEATURES = [
638+
"h2",
639+
"h3",
640+
"h4",
641+
"bold",
642+
"italic",
643+
"ul",
644+
"ol",
645+
"link",
646+
"document-link",
647+
]
648+
NO_HEADING_RICH_TEXT_FEATURES = ["bold", "italic", "ul", "ol", "link", "document-link"]
637649
WAGTAILADMIN_RICH_TEXT_EDITORS = {
638650
"default": {
639651
"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea",
640652
"OPTIONS": {
641-
"features": [
642-
"h2",
643-
"h3",
644-
"h4",
645-
"bold",
646-
"italic",
647-
"ul",
648-
"ol",
649-
"link",
650-
"document-link",
651-
]
653+
"features": DEFAULT_RICH_TEXT_FEATURES,
652654
},
653655
},
654656
}

0 commit comments

Comments
 (0)