Skip to content

Commit

Permalink
add some more block types (#1573)
Browse files Browse the repository at this point in the history
* add some more block types

* use cta for top links, reduce options in link groups

* separate link and ctas, add cta config

* fussing with styling options

* squash migrations

* more blocks

* merge migrations

* use link instead of cta for landing page layout

---------

Co-authored-by: Michael Volo <[email protected]>
  • Loading branch information
TomWoodward and mwvolo authored Jul 26, 2024
1 parent 9457a2e commit ab97c60
Show file tree
Hide file tree
Showing 15 changed files with 9,361 additions and 7 deletions.
68 changes: 62 additions & 6 deletions pages/custom_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LinkBlock(blocks.StreamBlock):
external = blocks.URLBlock(required=False)
internal = blocks.PageChooserBlock(required=False)
document = DocumentChooserBlock(required=False)
anchor = blocks.CharBlock(required=False)

class Meta:
icon = 'link'
Expand All @@ -46,26 +47,76 @@ def get_api_representation(self, value, context=None):
'value': child.value.url_path,
'type': child.block_type,
}
elif child.block_type == 'anchor':
return {
'value': "#{anchor}".format(anchor=child.value),
'type': child.block_type,
}
else:
return None


class CTALinkBlock(blocks.StructBlock):
class LinkInfoBlock(blocks.StructBlock):
text = blocks.CharBlock(required=True)
aria_label = blocks.CharBlock(required=False)
target = LinkBlock(required=True)

class Meta:
icon = 'placeholder'
label = "Link"

class CTALinkBlock(LinkInfoBlock):
text = blocks.CharBlock(required=True)
aria_label = blocks.CharBlock(required=False)
target = LinkBlock(required=True)
config = blocks.StreamBlock([
('style', blocks.ChoiceBlock(choices=[
('orange', 'Orange'),
('white', 'White'),
('blue_outline', 'Blue Outline'),
('deep_green_outline', 'Deep Green Outline'),
], default='descending')),
], block_counts={
'style': {'max_num': 1},
}, required=False)

class Meta:
icon = 'placeholder'
label = "Call to Action"


class LinksGroupBlock(blocks.StructBlock):
links = blocks.ListBlock(
LinkInfoBlock(required=False, label="Link"),
default=[], label='Links'
)
config = blocks.StreamBlock([
('color', blocks.ChoiceBlock(choices=[
('white', 'White'),
('blue', 'Blue'),
('deep-green', 'Deep Green'),
], default='descending')),
], block_counts={
'color': {'max_num': 1},
}, required=False)

class Meta:
icon = 'placeholder'
label = "Links Group"

class CTAButtonBarBlock(blocks.StructBlock):
actions = blocks.ListBlock(CTALinkBlock(required=False, label="Button"),
default=[],
max_num=2,
label='Actions'
)
actions = blocks.ListBlock(
CTALinkBlock(required=False, label="Button"),
default=[], max_num=2, label='Actions'
)
config = blocks.StreamBlock([
('priority', blocks.ChoiceBlock(choices=[
('descending', 'Descending'),
('equal', 'Equal'),
], default='descending')),
], block_counts={
'priority': {'max_num': 1},
}, required=False)

class Meta:
icon = 'placeholder'
Expand All @@ -88,6 +139,11 @@ def get_api_representation(self, value, context=None):
except AttributeError:
return None

class QuoteBlock(StructBlock):
image = APIImageChooserBlock()
content = blocks.RichTextBlock()
name = blocks.CharBlock()
title = blocks.CharBlock(requred=False)

class DividerBlock(StructBlock):
image = APIImageChooserBlock()
Expand Down

Large diffs are not rendered by default.

611 changes: 611 additions & 0 deletions pages/migrations/0137_alter_rootpage_body_alter_rootpage_layout.py

Large diffs are not rendered by default.

676 changes: 676 additions & 0 deletions pages/migrations/0138_alter_rootpage_body.py

Large diffs are not rendered by default.

698 changes: 698 additions & 0 deletions pages/migrations/0139_alter_rootpage_body.py

Large diffs are not rendered by default.

716 changes: 716 additions & 0 deletions pages/migrations/0140_alter_rootpage_body.py

Large diffs are not rendered by default.

734 changes: 734 additions & 0 deletions pages/migrations/0141_alter_rootpage_body.py

Large diffs are not rendered by default.

786 changes: 786 additions & 0 deletions pages/migrations/0142_alter_rootpage_body.py

Large diffs are not rendered by default.

985 changes: 985 additions & 0 deletions pages/migrations/0143_alter_rootpage_body_alter_rootpage_layout.py

Large diffs are not rendered by default.

985 changes: 985 additions & 0 deletions pages/migrations/0144_alter_rootpage_body_alter_rootpage_layout.py

Large diffs are not rendered by default.

989 changes: 989 additions & 0 deletions pages/migrations/0145_alter_rootpage_body_alter_rootpage_layout.py

Large diffs are not rendered by default.

972 changes: 972 additions & 0 deletions pages/migrations/0146_alter_rootpage_body.py

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions pages/migrations/0147_merge_20240725_1221.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 5.0.7 on 2024-07-25 17:21

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("pages", "0137_alter_rootpage_promote_image"),
("pages", "0146_alter_rootpage_body"),
]

operations = []
71 changes: 71 additions & 0 deletions pages/migrations/0148_alter_rootpage_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generated by Django 5.0.7 on 2024-07-25 17:31

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("pages", "0147_merge_20240725_1221"),
]

operations = [
migrations.AlterField(
model_name="rootpage",
name="layout",
field=wagtail.fields.StreamField(
[
("default", wagtail.blocks.StructBlock([])),
(
"landing",
wagtail.blocks.StructBlock(
[
(
"nav_links",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("text", wagtail.blocks.CharBlock(required=True)),
("aria_label", wagtail.blocks.CharBlock(required=False)),
(
"target",
wagtail.blocks.StreamBlock(
[
("external", wagtail.blocks.URLBlock(required=False)),
(
"internal",
wagtail.blocks.PageChooserBlock(required=False),
),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(
required=False
),
),
("anchor", wagtail.blocks.CharBlock(required=False)),
],
required=True,
),
),
],
label="Link",
required=False,
),
default=[],
label="Nav Links",
),
)
],
label="Landing Page",
),
),
],
blank=True,
default=[],
use_json_field=True,
),
),
]
22 changes: 21 additions & 1 deletion pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
DividerBlock, \
APIRichTextBlock, \
CTAButtonBarBlock, \
LinksGroupBlock, \
QuoteBlock, \
LinkInfoBlock, \
CTALinkBlock

from .custom_fields import Group
Expand Down Expand Up @@ -82,6 +85,11 @@
('text', APIRichTextBlock()),
('html', blocks.RawHTMLBlock()),
('cta_block', CTAButtonBarBlock()),
('links_group', LinksGroupBlock()),
('quote', QuoteBlock()),
('faq', blocks.StreamBlock([
('faq', FAQBlock()),
]))
]

# we have one RootPage, which is the parent of all other pages
Expand All @@ -92,7 +100,7 @@ class RootPage(Page):
('default', blocks.StructBlock([
])),
('landing', blocks.StructBlock([
('nav_links', blocks.ListBlock(CTALinkBlock(required=False, label="Link"),
('nav_links', blocks.ListBlock(LinkInfoBlock(required=False, label="Link"),
default=[],
label='Nav Links'
)),
Expand All @@ -105,6 +113,11 @@ class RootPage(Page):
('image', APIImageChooserBlock(required=False)),
('image_alt', blocks.CharBlock(required=False)),
('config', blocks.StreamBlock([
('id', blocks.RegexBlock(
regex=r'[a-zA-Z0-9\-_]',
help_text='html id of this element. eg: cool_section',
error_mssages={'invalid': 'not a valid id.'}
)),
('image_alignment', blocks.ChoiceBlock(choices=HERO_IMAGE_ALIGNMENT_CHOICES)),
('image_size', blocks.ChoiceBlock(choices=HERO_IMAGE_SIZE_CHOICES)),
('padding', blocks.IntegerBlock(min_value=0, help_text='Padding multiplier. default 0.')),
Expand All @@ -114,6 +127,7 @@ class RootPage(Page):
error_mssages={'invalid': 'not a valid hex color.'}
)),
], block_counts={
'id': {'max_num': 1},
'image_alignment': {'max_num': 1},
'image_size': {'max_num': 1},
'padding': {'max_num': 1},
Expand All @@ -123,6 +137,11 @@ class RootPage(Page):
('section', blocks.StructBlock([
('content', blocks.StreamBlock(SECTION_CONTENT_BLOCKS)),
('config', blocks.StreamBlock([
('id', blocks.RegexBlock(
regex=r'[a-zA-Z0-9\-_]',
help_text='html id of this element. eg: cool_section',
error_mssages={'invalid': 'not a valid id.'}
)),
('background_color', blocks.RegexBlock(
regex=r'#[a-zA-Z0-9]{6}',
help_text='eg: #ff0000',
Expand All @@ -135,6 +154,7 @@ class RootPage(Page):
('right', 'Right'),
], default='left')),
], block_counts={
'id': {'max_num': 1},
'background_color': {'max_num': 1},
'padding': {'max_num': 1},
'text_alignment': {'max_num': 1},
Expand Down

0 comments on commit ab97c60

Please sign in to comment.