diff --git a/server/books/schema/mutations/utils.py b/server/books/schema/mutations/utils.py index fcbd0c3d..2f52bcf9 100644 --- a/server/books/schema/mutations/utils.py +++ b/server/books/schema/mutations/utils.py @@ -15,6 +15,10 @@ from assignments.models import Assignment from books.models import ContentBlock +class AssignmentParameterException(Exception): + pass + + def newlines_to_paragraphs(text): parts = re.split(r'[\r\n]+', text) paragraphs = ['
{}
'.format(p.strip()) for p in parts] @@ -32,7 +36,7 @@ ALLOWED_BLOCKS = ( ) -def handle_content_block(content, context, module, allowed_blocks=ALLOWED_BLOCKS): +def handle_content_block(content, context=None, module=None, allowed_blocks=ALLOWED_BLOCKS): # todo: add all the content blocks # todo: sanitize user inputs! if content['type'] not in allowed_blocks: @@ -45,6 +49,10 @@ def handle_content_block(content, context, module, allowed_blocks=ALLOWED_BLOCKS 'text': newlines_to_paragraphs(bleach.clean(content['value']['text'], strip=True)) }} elif content['type'] == 'assignment': + if module is None: + 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'],