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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 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,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
SharmaineLim marked this conversation as resolved.
Show resolved Hide resolved


class DivisionSignpostCardBlock(blocks.StructBlock):
class ColourTheme(models.TextChoices):
CORAL = "theme-coral", "Coral"
helenb marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -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()
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 }}">
{{ card.get_heading }}
{{ 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