Skip to content

Commit

Permalink
TWE-39 Add a new block for textual statistic groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bmispelon committed Feb 11, 2025
1 parent 9e2859d commit 53d5378
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tbx/core/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,11 +1050,21 @@ class Meta:
label_format = "{headline_number} {description} {further_details}"


class NumericStatisticsGroupBlock(blocks.StructBlock):
class AbstractStatisticsGroupBlock(blocks.StructBlock):
"""
A base class for shared fields between numeric and textual stat blocks.
"""

title = blocks.CharBlock(max_length=255, required=False)
intro = blocks.RichTextBlock(
features=settings.NO_HEADING_RICH_TEXT_FEATURES, required=False
)

class Meta:
abstract = True


class NumericStatisticsGroupBlock(AbstractStatisticsGroupBlock):
statistics = blocks.ListBlock(
NumericStatisticsBlock(),
max_num=4,
Expand Down Expand Up @@ -1088,6 +1098,22 @@ class Meta:
icon = "info-circle"


class TextualStatisticsGroupBlock(AbstractStatisticsGroupBlock):
statistics = blocks.ListBlock(
TextualStatisticsBlock(),
max_num=4,
min_num=1,
)

class Meta:
group = "Custom"
icon = "table"
label = "Textual statistics"
template = (
"patterns/molecules/streamfield/blocks/textual_stats_group_block.html"
)


class TypedTableBlock(blocks.StructBlock):
table = WagtailTypedTableBlock(
[
Expand Down
2 changes: 2 additions & 0 deletions tbx/divisions/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
NumericStatisticsGroupBlock,
PartnersBlock,
StoryBlock,
TextualStatisticsGroupBlock,
)


class DivisionStoryBlock(StoryBlock):
four_photo_collage = FourPhotoCollageBlock()
introduction_with_images = IntroductionWithImagesBlock()
numeric_statistics = NumericStatisticsGroupBlock()
textual_statistics = TextualStatisticsGroupBlock()
partners_block = PartnersBlock()
featured_services = FeaturedServicesBlock()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load wagtailcore_tags wagtailimages_tags %}
<div class="grid__stats-group stats-group">
{% if value.title %}
{% include "patterns/atoms/motif-heading/motif-heading.html" with heading_level=2 heading=value.title classes="motif-heading motif-heading--two-c motif-heading--static stats-group__heading" %}
{% endif %}
{% if value.intro %}
<div class="text text--five stats-group__intro">{{ value.intro|richtext }}</div>
{% endif %}
{# Stats #}
{% include "patterns/molecules/streamfield/blocks/stats_textual.html" with value=value.statistics %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
context:
value:
title: Lighting little fires
intro: 'Torchbox has been supporting charities since the start of the digital era. Some of the stats we&apos;re particularly proud of:'
statistics:
- headline_text: Reduction in accessibility issues
further_details: '*There might be some sub text here that contextualises this result'
- headline_text: General increase in return visitors
further_details: '*There might be some sub text here that contextualises this result'
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ <h2 class="underline mt-8 mb-2">Numeric stats group block</h2>
{% include "patterns/molecules/streamfield/blocks/numeric_stats_group_block.html" %}
</div>

<div>
<h2 class="underline mt-8 mb-2">Textual stats group block</h2>
{% include "patterns/molecules/streamfield/blocks/textual_stats_group_block.html" %}
</div>

<div>
<h2 class="underline mt-8 mb-2">Event block</h2>
{% include "patterns/molecules/streamfield/blocks/event_block.html" %}
Expand Down

0 comments on commit 53d5378

Please sign in to comment.