diff --git a/etna/core/blocks/__init__.py b/etna/core/blocks/__init__.py index 372681e23..97da42fcd 100644 --- a/etna/core/blocks/__init__.py +++ b/etna/core/blocks/__init__.py @@ -1,3 +1,4 @@ +from .accordion import AccordionsBlock from .base import SectionDepthAwareStructBlock from .cta import ButtonBlock, CallToActionBlock, LargeCardLinksBlock from .document import DocumentsBlock @@ -25,6 +26,7 @@ from .video import YouTubeBlock __all__ = [ + "AccordionsBlock", "APIPageChooserBlock", "AuthorPromotedPagesBlock", "ButtonBlock", diff --git a/etna/core/blocks/accordion.py b/etna/core/blocks/accordion.py new file mode 100644 index 000000000..0cf95e18c --- /dev/null +++ b/etna/core/blocks/accordion.py @@ -0,0 +1,32 @@ +from django.conf import settings + +from wagtail import blocks + +from .document import DocumentsBlock +from .paragraph import APIRichTextBlock +from .tables import TableBlock + + +class AccordionContentBlock(blocks.StreamBlock): + text = APIRichTextBlock( + required=True, features=settings.RESTRICTED_RICH_TEXT_FEATURES + ) + table = TableBlock() + documents = DocumentsBlock() + + class Meta: + icon = "list-ul" + label = "Body" + + +class AccordionBlock(blocks.StructBlock): + title = blocks.CharBlock(required=True) + body = AccordionContentBlock() + + class Meta: + icon = "list-ul" + label = "Accordion Item" + + +class AccordionsBlock(blocks.StructBlock): + items = blocks.ListBlock(AccordionBlock()) diff --git a/etna/generic_pages/blocks.py b/etna/generic_pages/blocks.py index c609251ab..806fc00bd 100644 --- a/etna/generic_pages/blocks.py +++ b/etna/generic_pages/blocks.py @@ -1,6 +1,7 @@ from wagtail import blocks from etna.core.blocks import ( + AccordionsBlock, ButtonBlock, CallToActionBlock, ContentImageBlock, @@ -24,6 +25,7 @@ class SectionContentBlock(blocks.StreamBlock): + accordions = AccordionsBlock() button = ButtonBlock() call_to_action = CallToActionBlock() document = DocumentsBlock() diff --git a/etna/generic_pages/migrations/0022_alter_generalpage_body.py b/etna/generic_pages/migrations/0022_alter_generalpage_body.py new file mode 100644 index 000000000..bf06627a6 --- /dev/null +++ b/etna/generic_pages/migrations/0022_alter_generalpage_body.py @@ -0,0 +1,714 @@ +# Generated by Django 5.0.7 on 2024-07-17 13:19 +# 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.contrib.table_block.blocks +import wagtail.documents.blocks +import wagtail.fields +import wagtail.snippets.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("generic_pages", "0021_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( + [ + ( + "accordions", + wagtail.blocks.StructBlock( + [ + ( + "items", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + required=True + ), + ), + ( + "body", + wagtail.blocks.StreamBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ], + required=True, + ), + ), + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock(), + ), + ( + "documents", + wagtail.blocks.StructBlock( + [ + ( + "documents", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "file", + wagtail.documents.blocks.DocumentChooserBlock( + required=True + ), + ) + ] + ) + ), + ) + ] + ), + ), + ] + ), + ), + ] + ) + ), + ) + ] + ), + ), + ( + "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, + ), + ), + ] + ), + ), + ] + ), + ), + ( + "document", + wagtail.blocks.StructBlock( + [ + ( + "documents", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "file", + wagtail.documents.blocks.DocumentChooserBlock( + required=True + ), + ) + ] + ) + ), + ) + ] + ), + ), + ( + "do_dont_list", + wagtail.blocks.StructBlock( + [ + ( + "do", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ] + ), + ) + ], + icon="check", + label="Do item", + ), + label="Dos", + ), + ), + ( + "dont", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + ] + ), + ) + ], + icon="cross", + label="Don't item", + ), + label="Don'ts", + ), + ), + ] + ), + ), + ( + "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, + ), + ), + ] + ), + ), + ( + "inset_text", + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), + ( + "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, + ), + ) + ] + ), + ), + ( + "table", + wagtail.blocks.StructBlock( + [ + ( + "table", + wagtail.contrib.table_block.blocks.TableBlock( + table_options={ + "contextMenu": [ + "row_above", + "row_below", + "---------", + "col_left", + "col_right", + "---------", + "remove_row", + "remove_col", + "---------", + "undo", + "redo", + "---------", + "alignment", + ] + } + ), + ) + ] + ), + ), + ( + "warning_text", + wagtail.blocks.StructBlock( + [ + ( + "body", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), + ( + "youtube_video", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + label="Title", + max_length=100, + required=True, + ), + ), + ( + "video_id", + wagtail.blocks.CharBlock( + label="YouTube Video ID", + max_length=11, + required=True, + ), + ), + ( + "preview_image", + etna.core.blocks.image.APIImageChooserBlock( + label="Preview Image", + rendition_size="max-640x360", + required=False, + ), + ), + ] + ), + ), + ], + required=False, + ), + ), + ] + ), + ) + ], + blank=True, + null=True, + ), + ), + ]