From 97133434150386ed8e17c69d0105a6435c1c5336 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Mon, 17 Jun 2024 16:04:54 +0100 Subject: [PATCH 1/3] Update verbose_name_public properties (#1655) --- etna/api/tests/expected_results/article.json | 6 +++--- etna/api/tests/expected_results/arts.json | 2 +- etna/api/tests/expected_results/early_modern.json | 2 +- etna/api/tests/expected_results/focused_article.json | 4 ++-- etna/api/tests/expected_results/highlight_gallery.json | 4 ++-- etna/api/tests/expected_results/pages.json | 6 +++--- etna/api/tests/expected_results/postwar.json | 2 +- etna/authors/models.py | 1 + etna/collections/models.py | 4 ++-- etna/whatson/models.py | 1 + 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/etna/api/tests/expected_results/article.json b/etna/api/tests/expected_results/article.json index 0f2d06816..88555555e 100644 --- a/etna/api/tests/expected_results/article.json +++ b/etna/api/tests/expected_results/article.json @@ -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, @@ -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, @@ -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, diff --git a/etna/api/tests/expected_results/arts.json b/etna/api/tests/expected_results/arts.json index 766e59869..f9351605e 100644 --- a/etna/api/tests/expected_results/arts.json +++ b/etna/api/tests/expected_results/arts.json @@ -58,7 +58,7 @@ } }, "alert": null, - "type_label": "Explore by topic", + "type_label": "Topic", "teaser_text": "Teaser text", "teaser_image": { "id": 2, diff --git a/etna/api/tests/expected_results/early_modern.json b/etna/api/tests/expected_results/early_modern.json index 424d90d87..5ce755ab6 100644 --- a/etna/api/tests/expected_results/early_modern.json +++ b/etna/api/tests/expected_results/early_modern.json @@ -58,7 +58,7 @@ } }, "alert": null, - "type_label": "Explore by time period", + "type_label": "Time period", "teaser_text": "Teaser text", "teaser_image": { "id": 4, diff --git a/etna/api/tests/expected_results/focused_article.json b/etna/api/tests/expected_results/focused_article.json index 0041bd5be..c92d52c20 100644 --- a/etna/api/tests/expected_results/focused_article.json +++ b/etna/api/tests/expected_results/focused_article.json @@ -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, @@ -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, diff --git a/etna/api/tests/expected_results/highlight_gallery.json b/etna/api/tests/expected_results/highlight_gallery.json index 9bcdeb329..5b6c28969 100644 --- a/etna/api/tests/expected_results/highlight_gallery.json +++ b/etna/api/tests/expected_results/highlight_gallery.json @@ -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, @@ -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, diff --git a/etna/api/tests/expected_results/pages.json b/etna/api/tests/expected_results/pages.json index 4abbdb186..edd33c22b 100644 --- a/etna/api/tests/expected_results/pages.json +++ b/etna/api/tests/expected_results/pages.json @@ -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, @@ -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, @@ -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, diff --git a/etna/api/tests/expected_results/postwar.json b/etna/api/tests/expected_results/postwar.json index 6db7a4274..e0c51b77d 100644 --- a/etna/api/tests/expected_results/postwar.json +++ b/etna/api/tests/expected_results/postwar.json @@ -58,7 +58,7 @@ } }, "alert": null, - "type_label": "Explore by time period", + "type_label": "Time period", "teaser_text": "Teaser text", "teaser_image": { "id": 6, diff --git a/etna/authors/models.py b/etna/authors/models.py index a0600beb1..89982b05f 100644 --- a/etna/authors/models.py +++ b/etna/authors/models.py @@ -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" diff --git a/etna/collections/models.py b/etna/collections/models.py index a9d05ae6e..d5305d0f9 100644 --- a/etna/collections/models.py +++ b/etna/collections/models.py @@ -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", @@ -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", diff --git a/etna/whatson/models.py b/etna/whatson/models.py index 979033f6f..dc372bf63 100644 --- a/etna/whatson/models.py +++ b/etna/whatson/models.py @@ -59,6 +59,7 @@ class EventType(models.Model): class Meta: verbose_name = _("event type") verbose_name_plural = _("event types") + verbose_name_public = _("event") def __str__(self): return self.name From 1898d5dbbe915ace68b9f5151ef26213fb4290c6 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 18 Jun 2024 09:54:00 +0100 Subject: [PATCH 2/3] Disable Dependabot for npm --- .github/dependabot.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index debcb65a0..1b16db535 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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"] From 65a4eb317f268ff93b7a59f841fb7008fc110b71 Mon Sep 17 00:00:00 2001 From: James Biggs <62654785+jamesbiggs@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:04:04 +0100 Subject: [PATCH 3/3] DSRC-65: Call to action block (#1648) Co-authored-by: Andrew Hosgood --- etna/api/tests/expected_results/article.json | 2 +- etna/core/blocks/__init__.py | 4 +- etna/core/blocks/cta.py | 52 ++ etna/core/serializers/pages.py | 2 +- etna/generic_pages/blocks.py | 4 + .../migrations/0011_alter_generalpage_body.py | 473 ++++++++++++++++++ 6 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 etna/generic_pages/migrations/0011_alter_generalpage_body.py diff --git a/etna/api/tests/expected_results/article.json b/etna/api/tests/expected_results/article.json index 88555555e..abd71d46b 100644 --- a/etna/api/tests/expected_results/article.json +++ b/etna/api/tests/expected_results/article.json @@ -214,7 +214,7 @@ { "type": "featured_record_article", "value": { - "page": {} + "page": null }, "id": "b505f636-f3d1-4d4b-b368-69183e324e6e" }, diff --git a/etna/core/blocks/__init__.py b/etna/core/blocks/__init__.py index c335c6ac3..3670b34c8 100644 --- a/etna/core/blocks/__init__.py +++ b/etna/core/blocks/__init__.py @@ -1,5 +1,5 @@ from .base import SectionDepthAwareStructBlock -from .cta import LargeCardLinksBlock +from .cta import ButtonBlock, CallToActionBlock, LargeCardLinksBlock from .featured_content import ( FeaturedCollectionBlock, FeaturedRecordArticleBlock, @@ -22,6 +22,8 @@ __all__ = [ "APIPageChooserBlock", "AuthorPromotedPagesBlock", + "ButtonBlock", + "CallToActionBlock", "ContentImageBlock", "FeaturedRecordArticleBlock", "FeaturedCollectionBlock", diff --git a/etna/core/blocks/cta.py b/etna/core/blocks/cta.py index c6461043b..575b6bfa1 100644 --- a/etna/core/blocks/cta.py +++ b/etna/core/blocks/cta.py @@ -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): @@ -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" diff --git a/etna/core/serializers/pages.py b/etna/core/serializers/pages.py index c94cd4c93..44db26646 100644 --- a/etna/core/serializers/pages.py +++ b/etna/core/serializers/pages.py @@ -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): diff --git a/etna/generic_pages/blocks.py b/etna/generic_pages/blocks.py index 4e391c76a..e964d24d8 100644 --- a/etna/generic_pages/blocks.py +++ b/etna/generic_pages/blocks.py @@ -1,6 +1,8 @@ from wagtail import blocks from etna.core.blocks import ( + ButtonBlock, + CallToActionBlock, ContentImageBlock, FeaturedRecordArticleBlock, ParagraphBlock, @@ -16,6 +18,8 @@ class SectionContentBlock(blocks.StreamBlock): + button = ButtonBlock() + call_to_action = CallToActionBlock() featured_record_article = FeaturedRecordArticleBlock() image = ContentImageBlock() media = MediaBlock() diff --git a/etna/generic_pages/migrations/0011_alter_generalpage_body.py b/etna/generic_pages/migrations/0011_alter_generalpage_body.py new file mode 100644 index 000000000..193d94ef1 --- /dev/null +++ b/etna/generic_pages/migrations/0011_alter_generalpage_body.py @@ -0,0 +1,473 @@ +# Generated by Django 5.0.6 on 2024-06-17 11:08 +# etna:allowAlterField + +import etna.core.blocks.image +import etna.core.blocks.page_chooser +import etna.core.blocks.paragraph +import etna.media.blocks +import etna.records.blocks +import wagtail.blocks +import wagtail.fields +import wagtail.snippets.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("generic_pages", "0010_alter_generalpage_body"), + ] + + operations = [ + migrations.AlterField( + model_name="generalpage", + name="body", + field=wagtail.fields.StreamField( + [ + ( + "content_section", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Heading", max_length=100 + ), + ), + ( + "content", + wagtail.blocks.StreamBlock( + [ + ( + "button", + wagtail.blocks.StructBlock( + [ + ( + "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 + ), + ), + ( + "external_link", + wagtail.blocks.URLBlock( + required=False + ), + ), + ( + "accented", + wagtail.blocks.BooleanBlock( + help_text="Use the accented button style", + label="Accented", + required=False, + ), + ), + ] + ), + ), + ] + ), + ), + ( + "featured_record_article", + wagtail.blocks.StructBlock( + [ + ( + "page", + etna.core.blocks.page_chooser.APIPageChooserBlock( + label="Page", + page_type=[ + "articles.RecordArticlePage" + ], + required_api_fields=[ + "teaser_image" + ], + ), + ) + ] + ), + ), + ( + "image", + wagtail.blocks.StructBlock( + [ + ( + "image", + etna.core.blocks.image.APIImageChooserBlock( + rendition_size="max-900x900", + required=True, + ), + ), + ( + "alt_text", + wagtail.blocks.CharBlock( + help_text='Alternative (alt) text describes images when they fail to load, and is read aloud by assistive technologies. Use a maximum of 100 characters to describe your image. Check the guidance for tips on writing alt text.', + label="Alternative text", + max_length=100, + ), + ), + ( + "caption", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ], + help_text="If provided, displays directly below the image. Can be used to specify sources, transcripts or other useful metadata.", + label="Caption (optional)", + required=False, + ), + ), + ] + ), + ), + ( + "media", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="A descriptive title for the media block", + required=True, + ), + ), + ( + "background_image", + etna.core.blocks.image.APIImageChooserBlock( + help_text="A background image for the media block" + ), + ), + ( + "media", + etna.media.blocks.MediaChooserBlock(), + ), + ] + ), + ), + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), + ( + "promoted_item", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="Title of the promoted page", + label="Title", + max_length=100, + ), + ), + ( + "category", + wagtail.blocks.ChoiceBlock( + choices=[ + ( + "blog", + "Blog post", + ), + ( + "podcast", + "Podcast", + ), + ("video", "Video"), + ( + "video-external", + "External video", + ), + ( + "external-link", + "External link", + ), + ], + label="Category", + ), + ), + ( + "publication_date", + wagtail.blocks.CharBlock( + help_text="This is a free text field. Please enter date as per agreed format: 14 April 2021", + required=False, + ), + ), + ( + "author", + wagtail.blocks.CharBlock( + required=False + ), + ), + ( + "duration", + wagtail.blocks.CharBlock( + help_text="Podcast or video duration.", + label="Duration", + max_length=50, + required=False, + ), + ), + ( + "url", + wagtail.blocks.URLBlock( + help_text="URL for the external page", + label="External URL", + ), + ), + ( + "target_blank", + wagtail.blocks.BooleanBlock( + label="Should this URL open in a new tab?

Tick the box if 'yes'

", + required=False, + ), + ), + ( + "cta_label", + wagtail.blocks.CharBlock( + help_text="The text displayed on the button for your URL. If your URL links to an external site, please add the name of the site users will land on, and what they will find on this page. For example 'Watch our short film about Shakespeare on YouTube'.", + label="Call to action label", + max_length=50, + ), + ), + ( + "image", + wagtail.blocks.StructBlock( + [ + ( + "image", + etna.core.blocks.image.APIImageChooserBlock( + rendition_size="max-900x900", + required=True, + ), + ), + ( + "decorative", + wagtail.blocks.BooleanBlock( + default=False, + help_text='Decorative images are used for visual effect and do not add information to the content of a page. "Check the guidance to see if your image is decorative.', + label="Is this image decorative?

Tick the box if 'yes'

", + required=False, + ), + ), + ( + "alt_text", + wagtail.blocks.CharBlock( + help_text='Alternative (alt) text describes images when they fail to load, and is read aloud by assistive technologies. Use a maximum of 100 characters to describe your image. Decorative images do not require alt text. Check the guidance for tips on writing alt text.', + label="Image alternative text", + max_length=100, + required=False, + ), + ), + ], + label="Teaser image", + template="articles/blocks/images/blog-embed__image-container.html", + ), + ), + ( + "description", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ], + help_text="A description of the promoted page", + ), + ), + ] + ), + ), + ( + "promoted_list", + wagtail.blocks.StructBlock( + [ + ( + "category", + wagtail.snippets.blocks.SnippetChooserBlock( + "categories.Category" + ), + ), + ( + "summary", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ], + required=False, + ), + ), + ( + "promoted_items", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="The title of the target page", + max_length=100, + required=True, + ), + ), + ( + "description", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ], + help_text="A description of the target page", + required=False, + ), + ), + ( + "url", + wagtail.blocks.URLBlock( + required=True + ), + ), + ] + ) + ), + ), + ] + ), + ), + ( + "quote", + wagtail.blocks.StructBlock( + [ + ( + "quote", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ], + required=True, + ), + ), + ( + "attribution", + wagtail.blocks.CharBlock( + max_length=100, + required=False, + ), + ), + ] + ), + ), + ( + "record_links", + wagtail.blocks.StructBlock( + [ + ( + "items", + wagtail.blocks.ListBlock( + etna.records.blocks.RecordLinkBlock, + label="Items", + ), + ) + ] + ), + ), + ( + "sub_heading", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Sub-heading", + max_length=100, + ), + ) + ] + ), + ), + ], + required=False, + ), + ), + ] + ), + ) + ], + blank=True, + null=True, + ), + ), + ]