Enable editing of content blocks with assignments
This commit is contained in:
parent
c7cf6f7863
commit
016f6ce502
|
|
@ -21,6 +21,7 @@ class ContentElementValueInput(InputObjectType):
|
|||
description = graphene.String(description='To be used for basic_knowledge type')
|
||||
title = graphene.String(description='To be used for image_block, assignment type')
|
||||
assignment = graphene.String(description='To be used for assignment type')
|
||||
id = graphene.String(description='To be used for assignment type')
|
||||
|
||||
|
||||
class ContentElementInput(InputObjectType):
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
import bleach
|
||||
import re
|
||||
|
||||
from api.utils import get_object
|
||||
from assignments.models import Assignment
|
||||
from books.models import ContentBlock
|
||||
|
||||
|
|
@ -53,13 +54,20 @@ def handle_content_block(content, context=None, module=None, allowed_blocks=ALLO
|
|||
raise AssignmentParameterException('Module is missing for assignment') # todo: define better exception
|
||||
if context is None:
|
||||
raise AssignmentParameterException('Context is missing for assignment')
|
||||
assignment = Assignment.objects.create(
|
||||
title=content['value']['title'],
|
||||
assignment=content['value']['assignment'],
|
||||
owner=context.user,
|
||||
module=module,
|
||||
user_created=True
|
||||
)
|
||||
value = content['value']
|
||||
if value.get('id') is not None:
|
||||
assignment = get_object(Assignment, value.get('id'))
|
||||
assignment.title = value.get('title')
|
||||
assignment.assignment = value.get('assignment')
|
||||
assignment.save()
|
||||
else:
|
||||
assignment = Assignment.objects.create(
|
||||
title=value.get('title'),
|
||||
assignment=value.get('assignment'),
|
||||
owner=context.user,
|
||||
module=module,
|
||||
user_created=True
|
||||
)
|
||||
|
||||
return {
|
||||
'type': 'assignment',
|
||||
|
|
|
|||
Loading…
Reference in New Issue