Fix assignment creation

This commit is contained in:
Ramon Wenger 2018-10-18 10:00:03 +02:00
parent eef657e318
commit 13717c1371
2 changed files with 8 additions and 4 deletions

View File

@ -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()

View File

@ -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 {