Skip to content

Commit

Permalink
feat: add CustomRichTextBlock with customized richtext options
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Jul 20, 2021
1 parent 6a5e7cd commit dc0b3e1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
23 changes: 23 additions & 0 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,26 @@
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# Omitting the 'default' editor now leaves the original default editor intact,
# so it is no longer necessary to redefine 'default' when adding alternative editors.
WAGTAILADMIN_RICH_TEXT_EDITORS = {
"simple": {
"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea",
"OPTIONS": {
"features": [
"bold",
"italic",
"ol",
"ul",
"link",
"superscript",
"subscript",
"strikethrough",
"blockquote",
"hr",
"code",
]
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,28 @@ class BaseStreamBlock(StreamBlock):
icon="media",
template="blocks/embed_block.html",
)
table = TableBlock(template="blocks/table_block.html",)
table = TableBlock(
template="blocks/table_block.html",
)

class Meta:
required = False


class CustomRichTextBlock(StreamBlock):
"""
Define the custom blocks that `StreamField` will utilize
"""

paragraph_block = RichTextBlock(
icon="fa-paragraph", template="blocks/paragraph_block.html", editor="simple"
)

def get_api_representation(self, value, context=None):
# this hack based on https://github.com/wagtail/wagtail/issues/2695#issuecomment-457392434
api_representation = super().get_api_representation(value, context)
# we don't want the 'id
key_to_be_deleted = "id"
api_representation.pop(key_to_be_deleted, None)
api_representation["paragraph_block"] = str(value["paragraph_block"])
return api_representation

0 comments on commit dc0b3e1

Please sign in to comment.