diff --git a/server/books/schema/mutations/contentblock.py b/server/books/schema/mutations/contentblock.py index 8a6a04e7..c3044fd0 100644 --- a/server/books/schema/mutations/contentblock.py +++ b/server/books/schema/mutations/contentblock.py @@ -32,6 +32,7 @@ class MutateContentBlock(relay.ClientIDMutation): block_type = content_block_data.get('type', ContentBlock.NORMAL) content_block = get_object(ContentBlock, id_param) + module = content_block.get_parent().get_parent().specific if visibility_list is not None: for v in visibility_list: @@ -45,7 +46,7 @@ class MutateContentBlock(relay.ClientIDMutation): content_block.title = title if contents is not None: - content_block.contents = json.dumps([handle_content_block(c, info.context) for c in contents]) + content_block.contents = json.dumps([handle_content_block(c, info.context, module) for c in contents]) content_block.type = set_user_defined_block_type(block_type) @@ -96,7 +97,9 @@ class AddContentBlock(relay.ClientIDMutation): revision.publish() new_content_block.save() - new_content_block.contents = json.dumps([handle_content_block(c, context) for c in + module = new_content_block.get_parent().get_parent().specific + + new_content_block.contents = json.dumps([handle_content_block(c, context, module) for c in contents]) # can only do this after the content block has been saved new_content_block.save() diff --git a/server/books/schema/mutations/utils.py b/server/books/schema/mutations/utils.py index 812f5302..f2aae216 100644 --- a/server/books/schema/mutations/utils.py +++ b/server/books/schema/mutations/utils.py @@ -32,7 +32,7 @@ ALLOWED_BLOCKS = ( ) -def handle_content_block(content, context, allowed_blocks=ALLOWED_BLOCKS): +def handle_content_block(content, context, module, allowed_blocks=ALLOWED_BLOCKS): # todo: add all the content blocks # todo: sanitize user inputs! if content['type'] not in allowed_blocks: @@ -48,7 +48,8 @@ def handle_content_block(content, context, allowed_blocks=ALLOWED_BLOCKS): assignment = Assignment.objects.create( title=content['value']['title'], assignment=content['value']['assignment'], - owner=context.user + owner=context.user, + module=module, ) return {