Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TWE-2 - BE - Add division signpost block #314

Open
wants to merge 3 commits into
base: integration/2024-evolution
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tbx/core/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -297,6 +298,42 @@ class IconChoice(models.TextChoices):
WAGTAIL = "wagtail", "wagtail icon"


class DivisionSignpostCardBlock(blocks.StructBlock):
class ColourTheme(models.TextChoices):
CORAL = "theme-coral", "Coral"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check: is this the new theme naming for the whole site? Replacing banana etc?

Copy link
Collaborator

@ababic ababic Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something that could be quite reusable, too (The TextChoices). Maybe worth adding to a constants.py file or something similar?

Copy link
Collaborator Author

@SharmaineLim SharmaineLim Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block has a reduced number of available colours compared to the rest of the site.

The theme colours that will be available to the site are: coral, nebuline, lagoon and green, but for this block, only coral, nebuline and lagoon have been designed (for charity, public sector and wagtail respectively), so I made it its own subclass of colour options.

Design screenshot

image

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"


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
Expand Down Expand Up @@ -943,6 +980,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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load wagtailcore_tags wagtailimages_tags %}
<div>
{# Section heading #}
<h2>{{ value.title }}</h2>

{# Section intro #}
<div>{{ value.intro|richtext }}</div>

{# Signposting cards #}
<ul>
{% for card in value.cards %}
<li class="{{ card.card_colour }}">
{% firstof card.heading card.page.title %}
{{ card.description|richtext }}
{% image card.image fill-100x100 %}
<a href="{% pageurl card.page %}">{{ card.link_text }}</a>
</li>
{% endfor %}
</ul>
</div>
24 changes: 13 additions & 11 deletions tbx/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
Loading