From ed4616bd24c75d198b613dd28631cd9cae75c1cd Mon Sep 17 00:00:00 2001 From: Pawel Kowalski Date: Wed, 5 Sep 2018 16:40:27 +0200 Subject: [PATCH] Experiment with using wagtail api calls to serialize and deserialize StreamFields --- server/api/graphene_wagtail.py | 3 +++ server/book/blocks.py | 1 + server/book/factories.py | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/server/api/graphene_wagtail.py b/server/api/graphene_wagtail.py index f0e22a5a..e754de48 100644 --- a/server/api/graphene_wagtail.py +++ b/server/api/graphene_wagtail.py @@ -40,6 +40,9 @@ class GenericStreamFieldType(Scalar): return stream_data + # by_api = stream_value.stream_block.get_api_representation(stream_value) + # return by_api + @convert_django_field.register(StreamField) def convert_stream_field(field, registry=None): diff --git a/server/book/blocks.py b/server/book/blocks.py index 2d6d1a5a..c96802f5 100644 --- a/server/book/blocks.py +++ b/server/book/blocks.py @@ -2,6 +2,7 @@ from wagtail.core import blocks DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul'] + # link_block class LinkBlock(blocks.StructBlock): text = blocks.TextBlock() diff --git a/server/book/factories.py b/server/book/factories.py index de471eb5..9b84221e 100644 --- a/server/book/factories.py +++ b/server/book/factories.py @@ -94,6 +94,16 @@ class ContentBlockFactory(BasePageFactory): 'task': TextBlockFactory }) + # maybe this is a better way to create a strem field + # + + # contents = graphene.JSONString() + # + # contents_param = kwargs['contents'] + # new_content_block = ContentBlock(type=type_param, title=title) + # what_is_this = new_content_block.contents.stream_block.to_python(contents_param) + # new_content_block.contents = what_is_this + @classmethod def stream_field_magic(cls, kwargs, stream_field_name): if stream_field_name in kwargs: