From ec03c03c486b9a79037973f31c8d13a1c8401400 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Mon, 10 Sep 2018 10:21:25 +0200 Subject: [PATCH] Insert new content block at first position --- server/book/schema/mutations.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/book/schema/mutations.py b/server/book/schema/mutations.py index b53e0849..7d20ff46 100644 --- a/server/book/schema/mutations.py +++ b/server/book/schema/mutations.py @@ -113,8 +113,12 @@ class AddContentBlock(relay.ClientIDMutation): if parent is not None: parent_chapter = get_object(Chapter, parent).specific - parent_chapter.add_child(instance=new_content_block) - if after is not None: + first_sibling = parent_chapter.get_first_child() + if first_sibling is not None: + first_sibling.add_sibling(instance=new_content_block, pos='left') + else: + parent_chapter.add_child(instance=new_content_block) + elif after is not None: sibling = get_object(ContentBlock, after).specific sibling.add_sibling(instance=new_content_block, pos='right')