|
@@ -12,6 +12,17 @@ from wagtail.images import get_image_model
|
|
|
from wagtail.images.blocks import ImageChooserBlock
|
|
|
|
|
|
|
|
|
+def get_image_api_representation(image):
|
|
|
+ return {
|
|
|
+ "id": image.pk,
|
|
|
+ "title": image.title,
|
|
|
+ "meta": {
|
|
|
+ "type": type(image)._meta.app_label + "." + type(image).__name__,
|
|
|
+ "download_url": image.file.url,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
class CaptionedImageBlock(StructBlock):
|
|
|
"""
|
|
|
Custom `StructBlock` for utilizing images with associated caption and
|
|
@@ -34,6 +45,11 @@ class CaptionedImageBlock(StructBlock):
|
|
|
"caption": self.preview_image.description,
|
|
|
}
|
|
|
|
|
|
+ def get_api_representation(self, value, context=None):
|
|
|
+ data = super().get_api_representation(value, context)
|
|
|
+ data["image"] = get_image_api_representation(value["image"])
|
|
|
+ return data
|
|
|
+
|
|
|
class Meta:
|
|
|
icon = "image"
|
|
|
template = "blocks/captioned_image_block.html"
|
|
@@ -86,6 +102,11 @@ class BlockQuote(StructBlock):
|
|
|
description = "A quote with an optional attribution"
|
|
|
|
|
|
|
|
|
+class CustomEmbedBlock(EmbedBlock):
|
|
|
+ def get_api_representation(self, value, context=None):
|
|
|
+ return {"url": value.url, "html": value.html}
|
|
|
+
|
|
|
+
|
|
|
# StreamBlocks
|
|
|
class BaseStreamBlock(StreamBlock):
|
|
|
"""
|
|
@@ -110,7 +131,7 @@ class BaseStreamBlock(StreamBlock):
|
|
|
)
|
|
|
image_block = CaptionedImageBlock()
|
|
|
block_quote = BlockQuote()
|
|
|
- embed_block = EmbedBlock(
|
|
|
+ embed_block = CustomEmbedBlock(
|
|
|
help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
|
|
|
icon="media",
|
|
|
template="blocks/embed_block.html",
|