From 38c4c695cfb0818aba35524e8c7346824cd3391f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 27 Jun 2022 19:58:08 +0100 Subject: [PATCH] Setup features for richtext --- ...oglistpage_body_alter_blogpostpage_body.py | 94 +++++++++++++++++++ ...contentpage_body_alter_listingpage_body.py | 94 +++++++++++++++++++ website/common/streamfield.py | 19 +++- 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 website/blog/migrations/0005_alter_bloglistpage_body_alter_blogpostpage_body.py create mode 100644 website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py diff --git a/website/blog/migrations/0005_alter_bloglistpage_body_alter_blogpostpage_body.py b/website/blog/migrations/0005_alter_bloglistpage_body_alter_blogpostpage_body.py new file mode 100644 index 0000000..eb0be92 --- /dev/null +++ b/website/blog/migrations/0005_alter_bloglistpage_body_alter_blogpostpage_body.py @@ -0,0 +1,94 @@ +# Generated by Django 4.0.5 on 2022-06-27 18:57 + +import wagtail.blocks +import wagtail.embeds.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("blog", "0004_bloglistpage_body_blogpostpage_body"), + ] + + operations = [ + migrations.AlterField( + model_name="bloglistpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ( + "rich_text", + wagtail.blocks.RichTextBlock( + features=[ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "code", + "strikethrough", + ] + ), + ), + ( + "lorem", + wagtail.blocks.StructBlock( + [("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))] + ), + ), + ("html", wagtail.blocks.RawHTMLBlock()), + ], + blank=True, + use_json_field=True, + ), + ), + migrations.AlterField( + model_name="blogpostpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ( + "rich_text", + wagtail.blocks.RichTextBlock( + features=[ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "code", + "strikethrough", + ] + ), + ), + ( + "lorem", + wagtail.blocks.StructBlock( + [("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))] + ), + ), + ("html", wagtail.blocks.RawHTMLBlock()), + ], + blank=True, + use_json_field=True, + ), + ), + ] diff --git a/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py b/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py new file mode 100644 index 0000000..dd8e8dc --- /dev/null +++ b/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py @@ -0,0 +1,94 @@ +# Generated by Django 4.0.5 on 2022-06-27 18:57 + +import wagtail.blocks +import wagtail.embeds.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("common", "0005_contentpage_body_listingpage_body"), + ] + + operations = [ + migrations.AlterField( + model_name="contentpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ( + "rich_text", + wagtail.blocks.RichTextBlock( + features=[ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "code", + "strikethrough", + ] + ), + ), + ( + "lorem", + wagtail.blocks.StructBlock( + [("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))] + ), + ), + ("html", wagtail.blocks.RawHTMLBlock()), + ], + blank=True, + use_json_field=True, + ), + ), + migrations.AlterField( + model_name="listingpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ( + "rich_text", + wagtail.blocks.RichTextBlock( + features=[ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "code", + "strikethrough", + ] + ), + ), + ( + "lorem", + wagtail.blocks.StructBlock( + [("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))] + ), + ), + ("html", wagtail.blocks.RawHTMLBlock()), + ], + blank=True, + use_json_field=True, + ), + ), + ] diff --git a/website/common/streamfield.py b/website/common/streamfield.py index 7b5e987..c86c2b2 100644 --- a/website/common/streamfield.py +++ b/website/common/streamfield.py @@ -8,6 +8,23 @@ from wagtail.embeds.blocks import EmbedBlock IGNORE_PLAINTEXT_BLOCKS = (blocks.RawHTMLBlock, EmbedBlock) +RICH_TEXT_FEATURES = [ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "bold", + "italic", + "ol", + "ul", + "link", + "document-link", + "code", + "strikethrough", +] + class LoremBlock(blocks.StructBlock): paragraphs = blocks.IntegerBlock(min_value=1) @@ -27,7 +44,7 @@ class LoremBlock(blocks.StructBlock): def get_blocks() -> list[tuple[str, blocks.BaseBlock]]: return [ ("embed", EmbedBlock()), - ("rich_text", blocks.RichTextBlock()), + ("rich_text", blocks.RichTextBlock(features=RICH_TEXT_FEATURES)), ("lorem", LoremBlock()), ("html", blocks.RawHTMLBlock()), ]