Skip to content

Commit

Permalink
hero block restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Jul 12, 2024
1 parent 02f69dd commit 8345894
Show file tree
Hide file tree
Showing 6 changed files with 654 additions and 14 deletions.
13 changes: 8 additions & 5 deletions pages/custom_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_api_representation(self, value, context=None):
class Meta:
icon = 'doc-full'


class LinkStructValue(StructValue):
def url(self):
if self['external']:
Expand All @@ -25,7 +26,7 @@ def url(self):
elif self['document']:
return build_document_url(self['document'].url)
else:
return None
return 'link issue'

def text(self):
return self['text']
Expand All @@ -36,6 +37,7 @@ def link_aria_label(self):
def __bool__(self):
return bool(self.url())


class LinkBlock(blocks.StreamBlock):
external = blocks.URLBlock(required=False)
internal = blocks.PageChooserBlock(required=False)
Expand All @@ -45,16 +47,18 @@ class Meta:
icon = 'link'
max_num = 1


class CTAButtonBlock(blocks.StructBlock):
text = blocks.CharBlock(required=False)
link = LinkBlock(required=False)
link_aria_label = blocks.CharBlock(required=False)
aria_label = blocks.CharBlock(required=False)
target = LinkBlock(required=False)

class Meta:
icon = 'placeholder'
label = "CTA Button"
label = "Button"
value_class = LinkStructValue


class ImageFormatChoiceBlock(FieldBlock):
field = forms.ChoiceField(required=False, choices=(
('left', 'Wrap left'), ('right', 'Wrap right'), ('mid', 'Mid width'), ('full', 'Full width'),))
Expand Down Expand Up @@ -92,7 +96,6 @@ class Meta:
# value_class = ImageStructValue


# TODO: deprecate this block and move to the APIImageBlock
class APIImageChooserBlock(ImageChooserBlock):
def get_api_representation(self, value, context=None):
try:
Expand Down
134 changes: 134 additions & 0 deletions pages/migrations/0102_alter_rootpage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Generated by Django 5.0.7 on 2024-07-12 18:04

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


class Migration(migrations.Migration):

dependencies = [
("pages", "0101_alter_rootpage_body"),
]

operations = [
migrations.AlterField(
model_name="rootpage",
name="body",
field=wagtail.fields.StreamField(
[
(
"hero",
wagtail.blocks.StructBlock(
[
("text", pages.custom_blocks.APIRichTextBlock()),
("image", pages.custom_blocks.APIImageChooserBlock(required=False)),
(
"cta",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"link",
wagtail.blocks.StreamBlock(
[
("external", wagtail.blocks.URLBlock(required=False)),
(
"internal",
wagtail.blocks.PageChooserBlock(required=False),
),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(
required=False
),
),
],
required=False,
),
),
("link_aria_label", wagtail.blocks.CharBlock(required=False)),
],
required=False,
),
collapsed=True,
max_num=2,
),
),
]
),
),
(
"section",
wagtail.blocks.StreamBlock(
[
(
"cards",
wagtail.blocks.StructBlock(
[
("text", pages.custom_blocks.APIRichTextBlock()),
(
"cta",
wagtail.blocks.StructBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"link",
wagtail.blocks.StreamBlock(
[
(
"external",
wagtail.blocks.URLBlock(required=False),
),
(
"internal",
wagtail.blocks.PageChooserBlock(required=False),
),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(
required=False
),
),
],
required=False,
),
),
("link_aria_label", wagtail.blocks.CharBlock(required=False)),
],
label="CTA",
),
),
(
"config",
wagtail.blocks.StreamBlock(
[
(
"corner_style",
wagtail.blocks.ChoiceBlock(
choices=[("rounded", "Rounded"), ("square", "Square")]
),
)
],
max_num=1,
),
),
]
),
),
("text", pages.custom_blocks.APIRichTextBlock()),
("html", wagtail.blocks.RawHTMLBlock()),
],
icon="form",
),
),
("text", pages.custom_blocks.APIRichTextBlock()),
("html", wagtail.blocks.RawHTMLBlock()),
],
use_json_field=True,
),
),
]
160 changes: 160 additions & 0 deletions pages/migrations/0103_alter_rootpage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Generated by Django 5.0.7 on 2024-07-12 18:58

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


class Migration(migrations.Migration):

dependencies = [
("pages", "0102_alter_rootpage_body"),
]

operations = [
migrations.AlterField(
model_name="rootpage",
name="body",
field=wagtail.fields.StreamField(
[
(
"hero",
wagtail.blocks.StructBlock(
[
("text", pages.custom_blocks.APIRichTextBlock()),
("image", pages.custom_blocks.APIImageChooserBlock(required=False)),
(
"cta",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"link",
wagtail.blocks.StreamBlock(
[
("external", wagtail.blocks.URLBlock(required=False)),
(
"internal",
wagtail.blocks.PageChooserBlock(required=False),
),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(
required=False
),
),
],
required=False,
),
),
("link_aria_label", wagtail.blocks.CharBlock(required=False)),
],
required=False,
),
label="CTA",
max_num=2,
),
),
(
"config",
wagtail.blocks.StreamBlock(
[
(
"alignment",
wagtail.blocks.ChoiceBlock(
choices=[
("left", "Left"),
("right", "Right"),
("topLeft", "Top Left"),
("topRight", "Top Right"),
("bottomLeft", "Bottom Left"),
("bottomRight", "Bottom Right"),
]
),
),
(
"size",
wagtail.blocks.ChoiceBlock(
choices=[("auto", "Left"), ("curtain", "Right"), ("cover", "Cover")]
),
),
]
),
),
]
),
),
(
"section",
wagtail.blocks.StreamBlock(
[
(
"cards",
wagtail.blocks.StructBlock(
[
("text", pages.custom_blocks.APIRichTextBlock()),
(
"cta",
wagtail.blocks.StructBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"link",
wagtail.blocks.StreamBlock(
[
(
"external",
wagtail.blocks.URLBlock(required=False),
),
(
"internal",
wagtail.blocks.PageChooserBlock(required=False),
),
(
"document",
wagtail.documents.blocks.DocumentChooserBlock(
required=False
),
),
],
required=False,
),
),
("link_aria_label", wagtail.blocks.CharBlock(required=False)),
],
label="CTA",
),
),
(
"config",
wagtail.blocks.StreamBlock(
[
(
"corner_style",
wagtail.blocks.ChoiceBlock(
choices=[("rounded", "Rounded"), ("square", "Square")]
),
)
],
max_num=1,
),
),
]
),
),
("text", pages.custom_blocks.APIRichTextBlock()),
("html", wagtail.blocks.RawHTMLBlock()),
],
icon="form",
),
),
("text", pages.custom_blocks.APIRichTextBlock()),
("html", wagtail.blocks.RawHTMLBlock()),
],
use_json_field=True,
),
),
]
Loading

0 comments on commit 8345894

Please sign in to comment.