Update mutation to pass test
This commit is contained in:
parent
3034f77640
commit
b5ffb3ee29
|
|
@ -10,7 +10,7 @@ from books.models import ContentBlock, Chapter, SchoolClass
|
||||||
from books.schema.inputs import ContentBlockInput
|
from books.schema.inputs import ContentBlockInput
|
||||||
from ..nodes import ContentBlockNode
|
from ..nodes import ContentBlockNode
|
||||||
from core.utils import set_hidden_for, set_visible_for
|
from core.utils import set_hidden_for, set_visible_for
|
||||||
from .utils import handle_content_block, set_user_defined_block_type
|
from .utils import handle_content_block, handle_text, set_user_defined_block_type
|
||||||
|
|
||||||
|
|
||||||
class MutateContentBlock(relay.ClientIDMutation):
|
class MutateContentBlock(relay.ClientIDMutation):
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,15 @@ class AssignmentParameterException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def newlines_to_paragraphs(text):
|
def handle_text(text):
|
||||||
parts = re.split(r'[\r\n]+', text)
|
is_list = bool(re.search(r'<ul>', text))
|
||||||
paragraphs = ['<p>{}</p>'.format(p.strip()) for p in parts]
|
if is_list:
|
||||||
return '\n'.join(paragraphs)
|
# let's assume this is formatted correctly already, otherwise bleach or the browser should strip / ignore it
|
||||||
|
return text
|
||||||
|
else:
|
||||||
|
parts = re.split(r'[\r\n]+', text)
|
||||||
|
paragraphs = ['<p>{}</p>'.format(p.strip()) for p in parts]
|
||||||
|
return '\n'.join(paragraphs)
|
||||||
|
|
||||||
|
|
||||||
ALLOWED_BLOCKS = (
|
ALLOWED_BLOCKS = (
|
||||||
|
|
@ -49,7 +54,7 @@ def handle_content_block(content, context=None, module=None, allowed_blocks=ALLO
|
||||||
return {
|
return {
|
||||||
'type': 'text_block',
|
'type': 'text_block',
|
||||||
'value': {
|
'value': {
|
||||||
'text': newlines_to_paragraphs(bleach.clean(content['value']['text'], strip=True))
|
'text': handle_text(bleach.clean(content['value']['text'], strip=True))
|
||||||
}}
|
}}
|
||||||
elif content['type'] == 'assignment':
|
elif content['type'] == 'assignment':
|
||||||
if module is None:
|
if module is None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue