Fix bug in room creation

This commit is contained in:
Ramon Wenger 2018-10-22 20:08:34 +02:00
parent ec908e6b7a
commit f16e4db625
1 changed files with 9 additions and 1 deletions

View File

@ -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 = ['<p>{}</p>'.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'],