2
0
Эх сурвалжийг харах

Add custom get_api_representation for EmbedBlock

Sage Abdullah 4 сар өмнө
parent
commit
d0baa5d820

+ 6 - 1
bakerydemo/base/blocks.py

@@ -102,6 +102,11 @@ class BlockQuote(StructBlock):
         description = "A quote with an optional attribution"
         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
 # StreamBlocks
 class BaseStreamBlock(StreamBlock):
 class BaseStreamBlock(StreamBlock):
     """
     """
@@ -126,7 +131,7 @@ class BaseStreamBlock(StreamBlock):
     )
     )
     image_block = CaptionedImageBlock()
     image_block = CaptionedImageBlock()
     block_quote = BlockQuote()
     block_quote = BlockQuote()
-    embed_block = EmbedBlock(
+    embed_block = CustomEmbedBlock(
         help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
         help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
         icon="media",
         icon="media",
         template="blocks/embed_block.html",
         template="blocks/embed_block.html",