From 9a0d8b7744d9d109d659ea490a138ca9f609f05c Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 5 Jun 2024 11:29:14 +0100 Subject: [PATCH 01/25] Created DocumentBlock to add link text and a related file --- etna/core/blocks/document.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 etna/core/blocks/document.py diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py new file mode 100644 index 000000000..50481f76d --- /dev/null +++ b/etna/core/blocks/document.py @@ -0,0 +1,17 @@ +from wagtail import blocks +from wagtail.documents.blocks import DocumentChooserBlock + +class DocumentBlock(blocks.StructBlock): + """ + A block for embedding a document file in a page. + """ + + link_text = blocks.CharBlock( + required=True, + help_text="The text to display for the link to the document", + ) + file = DocumentChooserBlock(required=True) + + class Meta: + icon = "doc-full" + label = "Document" \ No newline at end of file From 2ccbc1ed3c469add8123115c1bab12ea43bce4f5 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 5 Jun 2024 11:29:53 +0100 Subject: [PATCH 02/25] Added DocumentBlock to the __init__ --- etna/core/blocks/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etna/core/blocks/__init__.py b/etna/core/blocks/__init__.py index 75584f143..6d27d2c05 100644 --- a/etna/core/blocks/__init__.py +++ b/etna/core/blocks/__init__.py @@ -1,5 +1,6 @@ from .base import SectionDepthAwareStructBlock from .cta import LargeCardLinksBlock +from .document import DocumentBlock from .featured_content import FeaturedRecordArticleBlock from .image import ContentImageBlock, ImageBlock, NoCaptionImageBlock from .page_chooser import APIPageChooserBlock @@ -12,6 +13,7 @@ __all__ = [ "APIPageChooserBlock", "ContentImageBlock", + "DocumentBlock", "FeaturedRecordArticleBlock", "ImageBlock", "NoCaptionImageBlock", From a7bb1dbaeb57d487178e935493b18ffec71f3a8c Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 5 Jun 2024 11:37:29 +0100 Subject: [PATCH 03/25] Added DocumentBlock to SectionContentBlock --- etna/articles/blocks.py | 2 + ...page_body_alter_focusedarticlepage_body.py | 800 ++++++++++++++++++ 2 files changed, 802 insertions(+) create mode 100644 etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py diff --git a/etna/articles/blocks.py b/etna/articles/blocks.py index 5f6e28220..af6ea9822 100644 --- a/etna/articles/blocks.py +++ b/etna/articles/blocks.py @@ -7,6 +7,7 @@ from etna.core.blocks import ( AuthorPromotedLinkBlock, ContentImageBlock, + DocumentBlock, FeaturedRecordArticleBlock, NoCaptionImageBlock, PageListBlock, @@ -192,6 +193,7 @@ class SectionContentBlock(blocks.StreamBlock): promoted_item = PromotedItemBlock() promoted_list = PromotedListBlock() record_links = RecordLinksBlock() + document = DocumentBlock() class ContentSectionBlock(SectionDepthAwareStructBlock): diff --git a/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py b/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py new file mode 100644 index 000000000..918a9d2b9 --- /dev/null +++ b/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py @@ -0,0 +1,800 @@ +# Generated by Django 5.0.6 on 2024-06-05 10:33 + +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.documents.blocks +import wagtail.fields +import wagtail.snippets.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("articles", "0106_alter_articlepage_body_alter_focusedarticlepage_body"), + ] + + operations = [ + migrations.AlterField( + model_name="articlepage", + name="body", + field=wagtail.fields.StreamField( + [ + ( + "content_section", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Heading", max_length=100 + ), + ), + ( + "content", + wagtail.blocks.StreamBlock( + [ + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), + ( + "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, + ), + ), + ] + ), + ), + ( + "sub_heading", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Sub-heading", + max_length=100, + ), + ) + ] + ), + ), + ( + "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(), + ), + ] + ), + ), + ( + "featured_record_article", + wagtail.blocks.StructBlock( + [ + ( + "page", + etna.core.blocks.page_chooser.APIPageChooserBlock( + label="Page", + page_type=[ + "articles.RecordArticlePage" + ], + required_api_fields=[ + "teaser_image" + ], + ), + ) + ] + ), + ), + ( + "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 + ), + ), + ] + ) + ), + ), + ] + ), + ), + ( + "record_links", + wagtail.blocks.StructBlock( + [ + ( + "items", + wagtail.blocks.ListBlock( + etna.records.blocks.RecordLinkBlock, + label="Items", + ), + ) + ] + ), + ), + ( + "document", + wagtail.blocks.StructBlock( + [ + ( + "link_text", + wagtail.blocks.CharBlock( + help_text="The text to display for the link to the document", + required=True, + ), + ), + ( + "file", + wagtail.documents.blocks.DocumentChooserBlock( + required=True + ), + ), + ] + ), + ), + ], + required=False, + ), + ), + ] + ), + ) + ], + blank=True, + null=True, + ), + ), + migrations.AlterField( + model_name="focusedarticlepage", + name="body", + field=wagtail.fields.StreamField( + [ + ( + "content_section", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Heading", max_length=100 + ), + ), + ( + "content", + wagtail.blocks.StreamBlock( + [ + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), + ( + "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, + ), + ), + ] + ), + ), + ( + "sub_heading", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + label="Sub-heading", + max_length=100, + ), + ) + ] + ), + ), + ( + "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(), + ), + ] + ), + ), + ( + "featured_record_article", + wagtail.blocks.StructBlock( + [ + ( + "page", + etna.core.blocks.page_chooser.APIPageChooserBlock( + label="Page", + page_type=[ + "articles.RecordArticlePage" + ], + required_api_fields=[ + "teaser_image" + ], + ), + ) + ] + ), + ), + ( + "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 + ), + ), + ] + ) + ), + ), + ] + ), + ), + ( + "record_links", + wagtail.blocks.StructBlock( + [ + ( + "items", + wagtail.blocks.ListBlock( + etna.records.blocks.RecordLinkBlock, + label="Items", + ), + ) + ] + ), + ), + ( + "document", + wagtail.blocks.StructBlock( + [ + ( + "link_text", + wagtail.blocks.CharBlock( + help_text="The text to display for the link to the document", + required=True, + ), + ), + ( + "file", + wagtail.documents.blocks.DocumentChooserBlock( + required=True + ), + ), + ] + ), + ), + ], + required=False, + ), + ), + ] + ), + ) + ], + blank=True, + null=True, + ), + ), + ] From 7316acdf29aa13e587a7f98022cc942edfc11696 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 5 Jun 2024 11:37:59 +0100 Subject: [PATCH 04/25] Formatting --- etna/core/blocks/document.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index 50481f76d..b760a739f 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -1,6 +1,7 @@ from wagtail import blocks from wagtail.documents.blocks import DocumentChooserBlock + class DocumentBlock(blocks.StructBlock): """ A block for embedding a document file in a page. @@ -14,4 +15,4 @@ class DocumentBlock(blocks.StructBlock): class Meta: icon = "doc-full" - label = "Document" \ No newline at end of file + label = "Document" From 9b368289767ee66b1fc88da737e9e3a27c9ad688 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 5 Jun 2024 11:39:42 +0100 Subject: [PATCH 05/25] Checked migration --- .../0107_alter_articlepage_body_alter_focusedarticlepage_body.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py b/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py index 918a9d2b9..89fabb978 100644 --- a/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py +++ b/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py @@ -1,4 +1,5 @@ # Generated by Django 5.0.6 on 2024-06-05 10:33 +# etna:allowAlterField import etna.core.blocks.image import etna.core.blocks.page_chooser From 2c8e3b980d36506326d2a681de2610a95783aa76 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Thu, 13 Jun 2024 10:50:53 +0100 Subject: [PATCH 06/25] Added `GENERIC_RICH_TEXT_FEATURES` for later use to add documents to RichText --- config/settings/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/settings/base.py b/config/settings/base.py index e3c1727c4..b57a888b8 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -334,6 +334,9 @@ "ol", "ul", ] +GENERIC_RICH_TEXT_FEATURES = RESTRICTED_RICH_TEXT_FEATURES + [ + "document-link", +] EXPANDED_RICH_TEXT_FEATURES = RESTRICTED_RICH_TEXT_FEATURES + [ "h2", "h3", From 267c80f3344bf01c99387c3e5d351fd201999dcf Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 18 Jun 2024 10:58:17 +0100 Subject: [PATCH 07/25] Deleted migration --- ...page_body_alter_focusedarticlepage_body.py | 801 ------------------ 1 file changed, 801 deletions(-) delete mode 100644 etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py diff --git a/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py b/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py deleted file mode 100644 index 89fabb978..000000000 --- a/etna/articles/migrations/0107_alter_articlepage_body_alter_focusedarticlepage_body.py +++ /dev/null @@ -1,801 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-05 10:33 -# 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.documents.blocks -import wagtail.fields -import wagtail.snippets.blocks -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("articles", "0106_alter_articlepage_body_alter_focusedarticlepage_body"), - ] - - operations = [ - migrations.AlterField( - model_name="articlepage", - name="body", - field=wagtail.fields.StreamField( - [ - ( - "content_section", - wagtail.blocks.StructBlock( - [ - ( - "heading", - wagtail.blocks.CharBlock( - label="Heading", max_length=100 - ), - ), - ( - "content", - wagtail.blocks.StreamBlock( - [ - ( - "paragraph", - wagtail.blocks.StructBlock( - [ - ( - "text", - etna.core.blocks.paragraph.APIRichTextBlock( - features=[ - "bold", - "italic", - "link", - "ol", - "ul", - ] - ), - ) - ] - ), - ), - ( - "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, - ), - ), - ] - ), - ), - ( - "sub_heading", - wagtail.blocks.StructBlock( - [ - ( - "heading", - wagtail.blocks.CharBlock( - label="Sub-heading", - max_length=100, - ), - ) - ] - ), - ), - ( - "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(), - ), - ] - ), - ), - ( - "featured_record_article", - wagtail.blocks.StructBlock( - [ - ( - "page", - etna.core.blocks.page_chooser.APIPageChooserBlock( - label="Page", - page_type=[ - "articles.RecordArticlePage" - ], - required_api_fields=[ - "teaser_image" - ], - ), - ) - ] - ), - ), - ( - "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 - ), - ), - ] - ) - ), - ), - ] - ), - ), - ( - "record_links", - wagtail.blocks.StructBlock( - [ - ( - "items", - wagtail.blocks.ListBlock( - etna.records.blocks.RecordLinkBlock, - label="Items", - ), - ) - ] - ), - ), - ( - "document", - wagtail.blocks.StructBlock( - [ - ( - "link_text", - wagtail.blocks.CharBlock( - help_text="The text to display for the link to the document", - required=True, - ), - ), - ( - "file", - wagtail.documents.blocks.DocumentChooserBlock( - required=True - ), - ), - ] - ), - ), - ], - required=False, - ), - ), - ] - ), - ) - ], - blank=True, - null=True, - ), - ), - migrations.AlterField( - model_name="focusedarticlepage", - name="body", - field=wagtail.fields.StreamField( - [ - ( - "content_section", - wagtail.blocks.StructBlock( - [ - ( - "heading", - wagtail.blocks.CharBlock( - label="Heading", max_length=100 - ), - ), - ( - "content", - wagtail.blocks.StreamBlock( - [ - ( - "paragraph", - wagtail.blocks.StructBlock( - [ - ( - "text", - etna.core.blocks.paragraph.APIRichTextBlock( - features=[ - "bold", - "italic", - "link", - "ol", - "ul", - ] - ), - ) - ] - ), - ), - ( - "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, - ), - ), - ] - ), - ), - ( - "sub_heading", - wagtail.blocks.StructBlock( - [ - ( - "heading", - wagtail.blocks.CharBlock( - label="Sub-heading", - max_length=100, - ), - ) - ] - ), - ), - ( - "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(), - ), - ] - ), - ), - ( - "featured_record_article", - wagtail.blocks.StructBlock( - [ - ( - "page", - etna.core.blocks.page_chooser.APIPageChooserBlock( - label="Page", - page_type=[ - "articles.RecordArticlePage" - ], - required_api_fields=[ - "teaser_image" - ], - ), - ) - ] - ), - ), - ( - "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 - ), - ), - ] - ) - ), - ), - ] - ), - ), - ( - "record_links", - wagtail.blocks.StructBlock( - [ - ( - "items", - wagtail.blocks.ListBlock( - etna.records.blocks.RecordLinkBlock, - label="Items", - ), - ) - ] - ), - ), - ( - "document", - wagtail.blocks.StructBlock( - [ - ( - "link_text", - wagtail.blocks.CharBlock( - help_text="The text to display for the link to the document", - required=True, - ), - ), - ( - "file", - wagtail.documents.blocks.DocumentChooserBlock( - required=True - ), - ), - ] - ), - ), - ], - required=False, - ), - ), - ] - ), - ) - ], - blank=True, - null=True, - ), - ), - ] From 75885ccc777170d260ab5ed68f8877628f25cc53 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 18 Jun 2024 11:51:10 +0100 Subject: [PATCH 08/25] Added DocumentBlock to GeneralPage --- etna/generic_pages/blocks.py | 2 + .../migrations/0012_alter_generalpage_body.py | 494 ++++++++++++++++++ 2 files changed, 496 insertions(+) create mode 100644 etna/generic_pages/migrations/0012_alter_generalpage_body.py diff --git a/etna/generic_pages/blocks.py b/etna/generic_pages/blocks.py index e964d24d8..4f0666427 100644 --- a/etna/generic_pages/blocks.py +++ b/etna/generic_pages/blocks.py @@ -4,6 +4,7 @@ ButtonBlock, CallToActionBlock, ContentImageBlock, + DocumentBlock, FeaturedRecordArticleBlock, ParagraphBlock, PromotedItemBlock, @@ -20,6 +21,7 @@ class SectionContentBlock(blocks.StreamBlock): button = ButtonBlock() call_to_action = CallToActionBlock() + document = DocumentBlock() featured_record_article = FeaturedRecordArticleBlock() image = ContentImageBlock() media = MediaBlock() diff --git a/etna/generic_pages/migrations/0012_alter_generalpage_body.py b/etna/generic_pages/migrations/0012_alter_generalpage_body.py new file mode 100644 index 000000000..2767a2534 --- /dev/null +++ b/etna/generic_pages/migrations/0012_alter_generalpage_body.py @@ -0,0 +1,494 @@ +# Generated by Django 5.0.6 on 2024-06-18 10:49 +# 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.documents.blocks +import wagtail.fields +import wagtail.snippets.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("generic_pages", "0011_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, + ), + ), + ] + ), + ), + ] + ), + ), + ( + "document", + wagtail.blocks.StructBlock( + [ + ( + "link_text", + wagtail.blocks.CharBlock( + help_text="The text to display for the link to the document", + required=True, + ), + ), + ( + "file", + wagtail.documents.blocks.DocumentChooserBlock( + required=True + ), + ), + ] + ), + ), + ( + "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, + ), + ), + ] From e833fe688fc548bec7dc7fb331da1832578263b1 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 18 Jun 2024 14:46:21 +0100 Subject: [PATCH 09/25] Document -> Documents --- etna/core/blocks/__init__.py | 4 ++-- etna/core/blocks/document.py | 11 +++++++++++ etna/generic_pages/blocks.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/etna/core/blocks/__init__.py b/etna/core/blocks/__init__.py index b350d711d..8accda9d9 100644 --- a/etna/core/blocks/__init__.py +++ b/etna/core/blocks/__init__.py @@ -1,6 +1,6 @@ from .base import SectionDepthAwareStructBlock from .cta import ButtonBlock, CallToActionBlock, LargeCardLinksBlock -from .document import DocumentBlock +from .document import DocumentsBlock from .featured_content import ( FeaturedCollectionBlock, FeaturedRecordArticleBlock, @@ -26,7 +26,7 @@ "ButtonBlock", "CallToActionBlock", "ContentImageBlock", - "DocumentBlock", + "DocumentsBlock", "FeaturedRecordArticleBlock", "FeaturedCollectionBlock", "ImageBlock", diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index b760a739f..0b63af6b6 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -16,3 +16,14 @@ class DocumentBlock(blocks.StructBlock): class Meta: icon = "doc-full" label = "Document" + +class DocumentsBlock(blocks.StructBlock): + """ + A block for embedding multiple document files in a page. + """ + + documents = blocks.ListBlock(DocumentBlock()) + + class Meta: + icon = "doc-full" + label = "Documents" \ No newline at end of file diff --git a/etna/generic_pages/blocks.py b/etna/generic_pages/blocks.py index 4f0666427..92511fa68 100644 --- a/etna/generic_pages/blocks.py +++ b/etna/generic_pages/blocks.py @@ -4,7 +4,7 @@ ButtonBlock, CallToActionBlock, ContentImageBlock, - DocumentBlock, + DocumentsBlock, FeaturedRecordArticleBlock, ParagraphBlock, PromotedItemBlock, @@ -21,7 +21,7 @@ class SectionContentBlock(blocks.StreamBlock): button = ButtonBlock() call_to_action = CallToActionBlock() - document = DocumentBlock() + document = DocumentsBlock() featured_record_article = FeaturedRecordArticleBlock() image = ContentImageBlock() media = MediaBlock() From 1eb7900ca190dbe1b62e36d434c1b94d031d7dba Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 15:19:25 +0100 Subject: [PATCH 10/25] Fixed migration --- .../migrations/0012_alter_generalpage_body.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/etna/generic_pages/migrations/0012_alter_generalpage_body.py b/etna/generic_pages/migrations/0012_alter_generalpage_body.py index 28e0fd2e6..c156c964f 100644 --- a/etna/generic_pages/migrations/0012_alter_generalpage_body.py +++ b/etna/generic_pages/migrations/0012_alter_generalpage_body.py @@ -174,6 +174,25 @@ class Migration(migrations.Migration): ] ), ), + ( + "inset_text", + wagtail.blocks.StructBlock( + [ + ( + "text", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ) + ] + ), + ), ( "media", wagtail.blocks.StructBlock( From 97ad4bf14bf82929ad536c16cdcf3a952489e5f7 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:05:36 +0100 Subject: [PATCH 11/25] Extended base DocumentModel with CustomDocument to add extent and description --- config/settings/base.py | 2 + etna/core/migrations/0004_customdocument.py | 88 +++++++++++++++++++++ etna/core/models/__init__.py | 1 + etna/core/models/documents.py | 12 +++ 4 files changed, 103 insertions(+) create mode 100644 etna/core/migrations/0004_customdocument.py create mode 100644 etna/core/models/documents.py diff --git a/config/settings/base.py b/config/settings/base.py index cb4953a0e..12aea9625 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -305,6 +305,8 @@ } } +WAGTAILDOCS_DOCUMENT_MODEL = 'core.CustomDocument' + WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage" # Custom password template for private pages diff --git a/etna/core/migrations/0004_customdocument.py b/etna/core/migrations/0004_customdocument.py new file mode 100644 index 000000000..439e7bc23 --- /dev/null +++ b/etna/core/migrations/0004_customdocument.py @@ -0,0 +1,88 @@ +# Generated by Django 5.0.6 on 2024-07-02 15:35 + +import django.db.models.deletion +import taggit.managers +import wagtail.models.media +import wagtail.search.index +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0003_set_page_uuid"), + ( + "taggit", + "0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx", + ), + ("wagtailcore", "0093_uploadedfile"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="CustomDocument", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=255, verbose_name="title")), + ("file", models.FileField(upload_to="documents", verbose_name="file")), + ( + "created_at", + models.DateTimeField(auto_now_add=True, verbose_name="created at"), + ), + ("file_size", models.PositiveIntegerField(editable=False, null=True)), + ( + "file_hash", + models.CharField(blank=True, editable=False, max_length=40), + ), + ("extent", models.CharField(blank=True, null=True)), + ("description", models.TextField(blank=True, null=True)), + ( + "collection", + models.ForeignKey( + default=wagtail.models.media.get_root_collection_id, + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="wagtailcore.collection", + verbose_name="collection", + ), + ), + ( + "tags", + taggit.managers.TaggableManager( + blank=True, + help_text=None, + through="taggit.TaggedItem", + to="taggit.Tag", + verbose_name="tags", + ), + ), + ( + "uploaded_by_user", + models.ForeignKey( + blank=True, + editable=False, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, + verbose_name="uploaded by user", + ), + ), + ], + options={ + "verbose_name": "document", + "verbose_name_plural": "documents", + "abstract": False, + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + ] diff --git a/etna/core/models/__init__.py b/etna/core/models/__init__.py index 0a370114f..24f5a8e63 100644 --- a/etna/core/models/__init__.py +++ b/etna/core/models/__init__.py @@ -1,4 +1,5 @@ from .basepage import * # noqa +from .documents import * # noqa from .forms import * # noqa from .mixins import * # noqa from .settings import * # noqa diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py new file mode 100644 index 000000000..b5025ef55 --- /dev/null +++ b/etna/core/models/documents.py @@ -0,0 +1,12 @@ +from django.db import models + +from wagtail.documents.models import Document, AbstractDocument + +class CustomDocument(AbstractDocument): + extent = models.CharField(blank=True, null=True) + description = models.TextField(blank=True, null=True) + + admin_form_fields = Document.admin_form_fields + ( + "extent", + "description", + ) \ No newline at end of file From e98430057e62f7ef3050f7b2ca1c258eb08c3570 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:06:21 +0100 Subject: [PATCH 12/25] Updated API representation of the DocumentBlock --- etna/core/blocks/document.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index 0b63af6b6..2578273d1 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -13,6 +13,29 @@ class DocumentBlock(blocks.StructBlock): ) file = DocumentChooserBlock(required=True) + def get_api_representation(self, value, context=None): + representation = super().get_api_representation(value, context) + + file = value.get("file") + + if file: + if file.file_size >= 1000000: + file_size = f"{((file.file_size/1024)/1024):.2f}MB" + else: + file_size = f"{(file.file_size/1024):.2f}KB" + + representation["file"] = { + "id": file.id, + "title": file.title, + "description": file.description, + "size": file_size, + "type": file.file_extension, + "extent": file.extent, + "url": file.file.url, + } + + return representation + class Meta: icon = "doc-full" label = "Document" From 68b8cfdbe05abf258f30aa26e9eccfe93f6b1665 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:08:38 +0100 Subject: [PATCH 13/25] Migrations --- .../migrations/0016_alter_generalpage_body.py | 599 ++++++++++++++++++ 1 file changed, 599 insertions(+) create mode 100644 etna/generic_pages/migrations/0016_alter_generalpage_body.py diff --git a/etna/generic_pages/migrations/0016_alter_generalpage_body.py b/etna/generic_pages/migrations/0016_alter_generalpage_body.py new file mode 100644 index 000000000..1f022e24d --- /dev/null +++ b/etna/generic_pages/migrations/0016_alter_generalpage_body.py @@ -0,0 +1,599 @@ +# Generated by Django 5.0.6 on 2024-07-02 16:06 +# 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.documents.blocks +import wagtail.fields +import wagtail.snippets.blocks +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("generic_pages", "0015_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, + ), + ), + ] + ), + ), + ] + ), + ), + ( + "document", + wagtail.blocks.StructBlock( + [ + ( + "documents", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "link_text", + wagtail.blocks.CharBlock( + help_text="The text to display for the link to the document", + required=True, + ), + ), + ( + "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, + ), + ) + ] + ), + ), + ( + "warning_text", + wagtail.blocks.StructBlock( + [ + ( + "heading", + wagtail.blocks.CharBlock( + help_text="Optional heading for the warning text, for screen readers", + required=False, + ), + ), + ( + "body", + etna.core.blocks.paragraph.APIRichTextBlock( + features=[ + "bold", + "italic", + "link", + "ol", + "ul", + ] + ), + ), + ] + ), + ), + ], + required=False, + ), + ), + ] + ), + ) + ], + blank=True, + null=True, + ), + ), + ] From 81894219157f2b277c15623e796908c99f966150 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:11:39 +0100 Subject: [PATCH 14/25] Formatting --- config/settings/base.py | 2 +- etna/core/blocks/document.py | 7 ++++--- etna/core/models/documents.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index 12aea9625..ff4dc7206 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -305,7 +305,7 @@ } } -WAGTAILDOCS_DOCUMENT_MODEL = 'core.CustomDocument' +WAGTAILDOCS_DOCUMENT_MODEL = "core.CustomDocument" WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage" diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index 2578273d1..d5cc63459 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -33,13 +33,14 @@ def get_api_representation(self, value, context=None): "extent": file.extent, "url": file.file.url, } - + return representation - + class Meta: icon = "doc-full" label = "Document" + class DocumentsBlock(blocks.StructBlock): """ A block for embedding multiple document files in a page. @@ -49,4 +50,4 @@ class DocumentsBlock(blocks.StructBlock): class Meta: icon = "doc-full" - label = "Documents" \ No newline at end of file + label = "Documents" diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index b5025ef55..8d2e85062 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -1,6 +1,7 @@ from django.db import models -from wagtail.documents.models import Document, AbstractDocument +from wagtail.documents.models import AbstractDocument, Document + class CustomDocument(AbstractDocument): extent = models.CharField(blank=True, null=True) @@ -9,4 +10,4 @@ class CustomDocument(AbstractDocument): admin_form_fields = Document.admin_form_fields + ( "extent", "description", - ) \ No newline at end of file + ) From ead48b338b4e6c0720a688a945a4d44ca647540a Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:13:02 +0100 Subject: [PATCH 15/25] More formatting... --- etna/core/blocks/document.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index d5cc63459..fa37b7eb3 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -20,9 +20,9 @@ def get_api_representation(self, value, context=None): if file: if file.file_size >= 1000000: - file_size = f"{((file.file_size/1024)/1024):.2f}MB" + file_size = f"{((file.file_size / 1024) / 1024):.2f}MB" else: - file_size = f"{(file.file_size/1024):.2f}KB" + file_size = f"{(file.file_size / 1024):.2f}KB" representation["file"] = { "id": file.id, From 9f6cc51680d7a7c401cfb07d02cc4325c578705f Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:16:01 +0100 Subject: [PATCH 16/25] Removed GENERIC_RICH_TEXT_FEATURES --- config/settings/base.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index ff4dc7206..5e4229c71 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -340,9 +340,6 @@ "ol", "ul", ] -GENERIC_RICH_TEXT_FEATURES = RESTRICTED_RICH_TEXT_FEATURES + [ - "document-link", -] EXPANDED_RICH_TEXT_FEATURES = RESTRICTED_RICH_TEXT_FEATURES + [ "h2", "h3", From 7b39a3a57df2f18c05eee9bbdb5615eb410ff16a Mon Sep 17 00:00:00 2001 From: James Biggs Date: Tue, 2 Jul 2024 17:35:36 +0100 Subject: [PATCH 17/25] Dropped to 1DP --- etna/core/blocks/document.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index fa37b7eb3..3f8104510 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -20,9 +20,9 @@ def get_api_representation(self, value, context=None): if file: if file.file_size >= 1000000: - file_size = f"{((file.file_size / 1024) / 1024):.2f}MB" + file_size = f"{((file.file_size / 1024) / 1024):.1f}MB" else: - file_size = f"{(file.file_size / 1024):.2f}KB" + file_size = f"{(file.file_size / 1024):.1f}KB" representation["file"] = { "id": file.id, From 0254156f9c0c00ba9b32e2013f7ec441f176a014 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 11:02:46 +0100 Subject: [PATCH 18/25] Removed link_text and updated migrations --- etna/core/blocks/document.py | 4 ---- ...lpage_body.py => 0017_alter_generalpage_body.py} | 13 +++---------- 2 files changed, 3 insertions(+), 14 deletions(-) rename etna/generic_pages/migrations/{0016_alter_generalpage_body.py => 0017_alter_generalpage_body.py} (98%) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index 3f8104510..35c4513d7 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -7,10 +7,6 @@ class DocumentBlock(blocks.StructBlock): A block for embedding a document file in a page. """ - link_text = blocks.CharBlock( - required=True, - help_text="The text to display for the link to the document", - ) file = DocumentChooserBlock(required=True) def get_api_representation(self, value, context=None): diff --git a/etna/generic_pages/migrations/0016_alter_generalpage_body.py b/etna/generic_pages/migrations/0017_alter_generalpage_body.py similarity index 98% rename from etna/generic_pages/migrations/0016_alter_generalpage_body.py rename to etna/generic_pages/migrations/0017_alter_generalpage_body.py index 1f022e24d..331a0e127 100644 --- a/etna/generic_pages/migrations/0016_alter_generalpage_body.py +++ b/etna/generic_pages/migrations/0017_alter_generalpage_body.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.6 on 2024-07-02 16:06 +# Generated by Django 5.0.6 on 2024-07-10 10:02 # etna:allowAlterField import etna.core.blocks.image @@ -16,7 +16,7 @@ class Migration(migrations.Migration): dependencies = [ - ("generic_pages", "0015_alter_generalpage_body"), + ("generic_pages", "0016_generalpage_intro"), ] operations = [ @@ -130,19 +130,12 @@ class Migration(migrations.Migration): wagtail.blocks.ListBlock( wagtail.blocks.StructBlock( [ - ( - "link_text", - wagtail.blocks.CharBlock( - help_text="The text to display for the link to the document", - required=True, - ), - ), ( "file", wagtail.documents.blocks.DocumentChooserBlock( required=True ), - ), + ) ] ) ), From 9e3a7d1ba1877e50a0b6952f9137b69f9304d9fd Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 11:54:41 +0100 Subject: [PATCH 19/25] Added pretty_file_size --- etna/core/blocks/document.py | 10 +++------- etna/core/models/documents.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/etna/core/blocks/document.py b/etna/core/blocks/document.py index 35c4513d7..715519a38 100644 --- a/etna/core/blocks/document.py +++ b/etna/core/blocks/document.py @@ -15,16 +15,12 @@ def get_api_representation(self, value, context=None): file = value.get("file") if file: - if file.file_size >= 1000000: - file_size = f"{((file.file_size / 1024) / 1024):.1f}MB" - else: - file_size = f"{(file.file_size / 1024):.1f}KB" - representation["file"] = { "id": file.id, "title": file.title, - "description": file.description, - "size": file_size, + "description": file.description or None, + "file_size": file.file_size, + "pretty_file_size": file.pretty_file_size, "type": file.file_extension, "extent": file.extent, "url": file.file.url, diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index 8d2e85062..827a822bd 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -7,6 +7,16 @@ class CustomDocument(AbstractDocument): extent = models.CharField(blank=True, null=True) description = models.TextField(blank=True, null=True) + @property + def pretty_file_size(self): + suffixes = ["B", "KB", "MB", "GB"] + i = 0 + pretty_file_size = self.file_size + while pretty_file_size >= 1024 and i < len(suffixes) - 1: + pretty_file_size /= 1024 + i += 1 + return f"{pretty_file_size:.1f}{suffixes[i]}" + admin_form_fields = Document.admin_form_fields + ( "extent", "description", From 61f99ae9a1d96b5f2d4679861e7632e1f91ac004 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 13:15:38 +0100 Subject: [PATCH 20/25] Changed to 1000 base --- etna/core/models/documents.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index 827a822bd..4a0a14647 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -12,8 +12,8 @@ def pretty_file_size(self): suffixes = ["B", "KB", "MB", "GB"] i = 0 pretty_file_size = self.file_size - while pretty_file_size >= 1024 and i < len(suffixes) - 1: - pretty_file_size /= 1024 + while pretty_file_size >= 1000 and i < len(suffixes) - 1: + pretty_file_size /= 1000 i += 1 return f"{pretty_file_size:.1f}{suffixes[i]}" From 768f8fc10fd83447d229128f584b66d1c815f9e2 Mon Sep 17 00:00:00 2001 From: James Biggs <62654785+jamesbiggs@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:26:29 +0100 Subject: [PATCH 21/25] Update etna/core/models/documents.py Co-authored-by: Andrew Hosgood --- etna/core/models/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index 4a0a14647..1b53127fd 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -9,7 +9,7 @@ class CustomDocument(AbstractDocument): @property def pretty_file_size(self): - suffixes = ["B", "KB", "MB", "GB"] + suffixes = ["B", "kB", "MB", "GB"] i = 0 pretty_file_size = self.file_size while pretty_file_size >= 1000 and i < len(suffixes) - 1: From 75779786f0f5bef41c003609ae323a67de89ea38 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 13:51:05 +0100 Subject: [PATCH 22/25] Differing decimal places, and strip .0 or .00 endings --- etna/core/models/documents.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index 1b53127fd..bd189248b 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -1,3 +1,5 @@ +import re + from django.db import models from wagtail.documents.models import AbstractDocument, Document @@ -15,7 +17,7 @@ def pretty_file_size(self): while pretty_file_size >= 1000 and i < len(suffixes) - 1: pretty_file_size /= 1000 i += 1 - return f"{pretty_file_size:.1f}{suffixes[i]}" + return re.sub(r'\.0+$', '', f"{pretty_file_size:.{max(i-1, 0)}f}{suffixes[i]}") admin_form_fields = Document.admin_form_fields + ( "extent", From 749a9aa599be91eb702832e4df3cd2a24af6ede7 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 13:54:56 +0100 Subject: [PATCH 23/25] Formatting --- etna/core/models/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index bd189248b..f05ac643b 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -17,7 +17,7 @@ def pretty_file_size(self): while pretty_file_size >= 1000 and i < len(suffixes) - 1: pretty_file_size /= 1000 i += 1 - return re.sub(r'\.0+$', '', f"{pretty_file_size:.{max(i-1, 0)}f}{suffixes[i]}") + return re.sub(r"\.0+$", "", f"{pretty_file_size:.{max(i-1, 0)}f}{suffixes[i]}") admin_form_fields = Document.admin_form_fields + ( "extent", From e7c2d0b9912a5e4dcbe1cb7c318bd1ada2591032 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 14:07:57 +0100 Subject: [PATCH 24/25] Further formatting --- etna/core/models/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index f05ac643b..491626427 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -17,7 +17,7 @@ def pretty_file_size(self): while pretty_file_size >= 1000 and i < len(suffixes) - 1: pretty_file_size /= 1000 i += 1 - return re.sub(r"\.0+$", "", f"{pretty_file_size:.{max(i-1, 0)}f}{suffixes[i]}") + return re.sub(r"\.0+$", "", f"{pretty_file_size:.{max(i - 1, 0)}f}{suffixes[i]}") admin_form_fields = Document.admin_form_fields + ( "extent", From 727fd4575fe73d9ed8582b9c08a94bc00d22cb28 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Wed, 10 Jul 2024 14:09:52 +0100 Subject: [PATCH 25/25] Even more formatting... --- etna/core/models/documents.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etna/core/models/documents.py b/etna/core/models/documents.py index 491626427..7d6aa382a 100644 --- a/etna/core/models/documents.py +++ b/etna/core/models/documents.py @@ -17,7 +17,9 @@ def pretty_file_size(self): while pretty_file_size >= 1000 and i < len(suffixes) - 1: pretty_file_size /= 1000 i += 1 - return re.sub(r"\.0+$", "", f"{pretty_file_size:.{max(i - 1, 0)}f}{suffixes[i]}") + return re.sub( + r"\.0+$", "", f"{pretty_file_size:.{max(i - 1, 0)}f}{suffixes[i]}" + ) admin_form_fields = Document.admin_form_fields + ( "extent",