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')
|
description = graphene.String(description='To be used for basic_knowledge type')
|
||||||
title = graphene.String(description='To be used for image_block, assignment type')
|
title = graphene.String(description='To be used for image_block, assignment type')
|
||||||
assignment = graphene.String(description='To be used for 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):
|
class ContentElementInput(InputObjectType):
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
import bleach
|
import bleach
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from api.utils import get_object
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
from books.models import ContentBlock
|
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
|
raise AssignmentParameterException('Module is missing for assignment') # todo: define better exception
|
||||||
if context is None:
|
if context is None:
|
||||||
raise AssignmentParameterException('Context is missing for assignment')
|
raise AssignmentParameterException('Context is missing for assignment')
|
||||||
assignment = Assignment.objects.create(
|
value = content['value']
|
||||||
title=content['value']['title'],
|
if value.get('id') is not None:
|
||||||
assignment=content['value']['assignment'],
|
assignment = get_object(Assignment, value.get('id'))
|
||||||
owner=context.user,
|
assignment.title = value.get('title')
|
||||||
module=module,
|
assignment.assignment = value.get('assignment')
|
||||||
user_created=True
|
assignment.save()
|
||||||
)
|
else:
|
||||||
|
assignment = Assignment.objects.create(
|
||||||
|
title=value.get('title'),
|
||||||
|
assignment=value.get('assignment'),
|
||||||
|
owner=context.user,
|
||||||
|
module=module,
|
||||||
|
user_created=True
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'type': 'assignment',
|
'type': 'assignment',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue