Skip to content

Commit

Permalink
Merge branch 'develop' into feature/DSRC-3-accordion-block
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs committed Jun 18, 2024
2 parents 1e9e488 + 65a4eb3 commit b24dd5a
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 52 deletions.
16 changes: 8 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ updates:
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
- package-ecosystem: "npm"
versioning-strategy: "widen"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
# - package-ecosystem: "npm"
# versioning-strategy: "widen"
# directory: "/"
# schedule:
# interval: "weekly"
# ignore:
# - dependency-name: "*"
# update-types: ["version-update:semver-patch"]
8 changes: 4 additions & 4 deletions etna/api/tests/expected_results/article.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
{
"type": "featured_record_article",
"value": {
"page": {}
"page": null
},
"id": "b505f636-f3d1-4d4b-b368-69183e324e6e"
},
Expand Down Expand Up @@ -318,7 +318,7 @@
"title": "arts",
"url": "/arts/",
"full_url": "http://localhost/arts/",
"type_label": "Explore by topic",
"type_label": "Topic",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand All @@ -344,7 +344,7 @@
"title": "early_modern",
"url": "/early_modern/",
"full_url": "http://localhost/early_modern/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand All @@ -368,7 +368,7 @@
"title": "postwar",
"url": "/postwar/",
"full_url": "http://localhost/postwar/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 6,
Expand Down
2 changes: 1 addition & 1 deletion etna/api/tests/expected_results/arts.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"alert": null,
"type_label": "Explore by topic",
"type_label": "Topic",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand Down
2 changes: 1 addition & 1 deletion etna/api/tests/expected_results/early_modern.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"alert": null,
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand Down
4 changes: 2 additions & 2 deletions etna/api/tests/expected_results/focused_article.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"title": "arts",
"url": "/arts/",
"full_url": "http://localhost/arts/",
"type_label": "Explore by topic",
"type_label": "Topic",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand All @@ -162,7 +162,7 @@
"title": "early_modern",
"url": "/early_modern/",
"full_url": "http://localhost/early_modern/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand Down
4 changes: 2 additions & 2 deletions etna/api/tests/expected_results/highlight_gallery.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"title": "arts",
"url": "/arts/",
"full_url": "http://localhost/arts/",
"type_label": "Explore by topic",
"type_label": "Topic",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand All @@ -176,7 +176,7 @@
"title": "early_modern",
"url": "/early_modern/",
"full_url": "http://localhost/early_modern/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand Down
6 changes: 3 additions & 3 deletions etna/api/tests/expected_results/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"title": "arts",
"url": "/arts/",
"full_url": "http://localhost/arts/",
"type_label": "Explore by topic",
"type_label": "Topic",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 2,
Expand Down Expand Up @@ -66,7 +66,7 @@
"title": "early_modern",
"url": "/early_modern/",
"full_url": "http://localhost/early_modern/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 4,
Expand All @@ -90,7 +90,7 @@
"title": "postwar",
"url": "/postwar/",
"full_url": "http://localhost/postwar/",
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 6,
Expand Down
2 changes: 1 addition & 1 deletion etna/api/tests/expected_results/postwar.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"alert": null,
"type_label": "Explore by time period",
"type_label": "Time period",
"teaser_text": "Teaser text",
"teaser_image": {
"id": 6,
Expand Down
1 change: 1 addition & 0 deletions etna/authors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class AuthorPage(BasePage):
class Meta:
verbose_name = "Author page"
verbose_name_plural = "Author pages"
verbose_name_public = "author"

# DataLayerMixin overrides
gtm_content_group = "Author page"
Expand Down
4 changes: 2 additions & 2 deletions etna/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class TopicExplorerPage(RequiredHeroImageMixin, AlertMixin, BasePageWithIntro):
class Meta:
verbose_name = _("topic page")
verbose_name_plural = _("topic pages")
verbose_name_public = _("explore by topic")
verbose_name_public = _("topic")

featured_article = models.ForeignKey(
"wagtailcore.Page",
Expand Down Expand Up @@ -486,7 +486,7 @@ class TimePeriodExplorerPage(RequiredHeroImageMixin, AlertMixin, BasePageWithInt
class Meta:
verbose_name = _("time period page")
verbose_name_plural = _("time period pages")
verbose_name_public = _("explore by time period")
verbose_name_public = _("time period")

featured_article = models.ForeignKey(
"wagtailcore.Page",
Expand Down
4 changes: 3 additions & 1 deletion etna/core/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .accordion import AccordionsBlock
from .base import SectionDepthAwareStructBlock
from .cta import LargeCardLinksBlock
from .cta import ButtonBlock, CallToActionBlock, LargeCardLinksBlock
from .featured_content import (
FeaturedCollectionBlock,
FeaturedRecordArticleBlock,
Expand All @@ -24,6 +24,8 @@
"AccordionsBlock",
"APIPageChooserBlock",
"AuthorPromotedPagesBlock",
"ButtonBlock",
"CallToActionBlock",
"ContentImageBlock",
"FeaturedRecordArticleBlock",
"FeaturedCollectionBlock",
Expand Down
52 changes: 52 additions & 0 deletions etna/core/blocks/cta.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _

from wagtail import blocks

from .page_chooser import APIPageChooserBlock
from .paragraph import APIRichTextBlock


class LargeCardLinksBlock(blocks.StructBlock):
Expand All @@ -29,3 +32,52 @@ def get_context(self, value, parent_context=None):
link_pages.append(page_2.specific)
context["link_pages"] = link_pages
return context


class ButtonBlock(blocks.StructBlock):
label = blocks.CharBlock()
link = APIPageChooserBlock(required=False)
external_link = blocks.URLBlock(required=False)
accented = blocks.BooleanBlock(
required=False,
help_text="Use the accented button style",
label="Accented",
)

def clean(self, value):
data = super().clean(value)

if data.get("link") and data.get("external_link"):
raise ValidationError(
"You must provide either a page link or an external link, not both."
)
elif not (data.get("link") or data.get("external_link")):
raise ValidationError(
"You must provide either a page link or an external link."
)

return data

def get_api_representation(self, value, context=None):
representation = {
"label": value["label"],
"href": value.get("external_link") or value["link"].full_url,
"accent": value.get("accented") or False,
}

return representation

class Meta:
icon = "link"
label = "Button"


class CallToActionBlock(blocks.StructBlock):
body = APIRichTextBlock(
max_length=100, features=settings.RESTRICTED_RICH_TEXT_FEATURES
)
button = ButtonBlock()

class Meta:
icon = "link"
label = "Call to action"
2 changes: 1 addition & 1 deletion etna/core/serializers/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_api_data(object, required_api_fields: list = []) -> dict:
api_representation[field.name] = get_field_data(
object=specific, field=field
)
return api_representation
return api_representation or None


class DefaultPageSerializer(serializers.Serializer):
Expand Down
4 changes: 4 additions & 0 deletions etna/generic_pages/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from etna.core.blocks import (
AccordionsBlock,
ButtonBlock,
CallToActionBlock,
ContentImageBlock,
FeaturedRecordArticleBlock,
ParagraphBlock,
Expand All @@ -18,6 +20,8 @@

class SectionContentBlock(blocks.StreamBlock):
accordion = AccordionsBlock()
button = ButtonBlock()
call_to_action = CallToActionBlock()
featured_record_article = FeaturedRecordArticleBlock()
image = ContentImageBlock()
media = MediaBlock()
Expand Down
99 changes: 73 additions & 26 deletions etna/generic_pages/migrations/0011_alter_generalpage_body.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-06-17 12:19
# Generated by Django 5.0.6 on 2024-06-17 11:08
# etna:allowAlterField

import etna.core.blocks.image
Expand Down Expand Up @@ -39,37 +39,84 @@ class Migration(migrations.Migration):
wagtail.blocks.StreamBlock(
[
(
"accordion",
"button",
wagtail.blocks.StructBlock(
[
(
"accordion",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"title",
wagtail.blocks.CharBlock(
required=True
),
"label",
wagtail.blocks.CharBlock(),
),
(
"link",
etna.core.blocks.page_chooser.APIPageChooserBlock(
required=False
),
),
(
"external_link",
wagtail.blocks.URLBlock(
required=False
),
),
(
"accented",
wagtail.blocks.BooleanBlock(
help_text="Use the accented button style",
label="Accented",
required=False,
),
),
]
),
),
(
"call_to_action",
wagtail.blocks.StructBlock(
[
(
"body",
etna.core.blocks.paragraph.APIRichTextBlock(
features=[
"bold",
"italic",
"link",
"ol",
"ul",
],
max_length=100,
),
),
(
"button",
wagtail.blocks.StructBlock(
[
(
"label",
wagtail.blocks.CharBlock(),
),
(
"link",
etna.core.blocks.page_chooser.APIPageChooserBlock(
required=False
),
(
"body",
etna.core.blocks.paragraph.APIRichTextBlock(
features=[
"bold",
"italic",
"link",
"ol",
"ul",
],
required=True,
),
),
(
"external_link",
wagtail.blocks.URLBlock(
required=False
),
]
)
),
(
"accented",
wagtail.blocks.BooleanBlock(
help_text="Use the accented button style",
label="Accented",
required=False,
),
),
]
),
)
),
]
),
),
Expand Down
Loading

0 comments on commit b24dd5a

Please sign in to comment.