Commit 47130c91 by Braden MacDonald

Remove <html> block in favour of Studio/Workbench's existing ones

parent 973c53db
from .answer import AnswerBlock from .answer import AnswerBlock
from .choice import ChoiceBlock from .choice import ChoiceBlock
from .html import HTMLBlock
from .mcq import MCQBlock from .mcq import MCQBlock
from .mrq import MRQBlock from .mrq import MRQBlock
from .message import MentoringMessageBlock from .message import MentoringMessageBlock
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Harvard
#
# Authors:
# Xavier Antoviaque <xavier@antoviaque.org>
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
# Imports ###########################################################
from lxml import etree
from xblock.core import XBlock
from xblock.fields import Scope, String
from xblock.fragment import Fragment
# Classes ###########################################################
class HTMLBlock(XBlock):
"""
Render content as HTML
"""
FIXED_CSS_CLASS = "html_child"
content = String(help="HTML content", scope=Scope.content, default="")
css_class = String(help="CSS Class[es] applied to wrapper div element", scope=Scope.content, default="")
@classmethod
def parse_xml(cls, node, runtime, keys, id_generator):
"""
Construct this XBlock from the given XML node.
"""
block = runtime.construct_xblock_from_class(cls, keys)
if node.get('class'): # Older API used "class" property, not "css_class"
node.set('css_class', node.get('css_class', node.get('class')))
del node.attrib['class']
block.css_class = node.get('css_class')
block.content = unicode(node.text or u"")
for child in node:
block.content += etree.tostring(child, encoding='unicode')
return block
def fallback_view(self, view_name, context=None):
""" Default view handler """
css_class = ' '.join(cls for cls in (self.css_class, self.FIXED_CSS_CLASS) if cls)
html = u'<div class="{classes}">{content}</div>'.format(classes=css_class, content=unicode(self.content))
return Fragment(html)
<div class="message {{ self.type }}">
{% if self.content %}
<p>{{ self.content }}</p>
{% endif %}
{{ child_content|safe }}
</div>
...@@ -190,7 +190,18 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC ...@@ -190,7 +190,18 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
if isinstance(child, MentoringMessageBlock): if isinstance(child, MentoringMessageBlock):
pass # TODO pass # TODO
else: else:
try:
child_fragment = child.render('mentoring_view', context) child_fragment = child.render('mentoring_view', context)
except NoSuchViewError:
if child.scope_ids.block_type == 'html':
if getattr(self.runtime, 'is_author_mode', False):
# html block doesn't support mentoring_view, and if we use student_view Studio will wrap
# it in HTML that we don't want in the preview. So just render its HTML directly:
child_fragment = Fragment(child.data)
else:
child_fragment = child.render('student_view', context)
else:
raise # This type of child is not supported.
fragment.add_frag_resources(child_fragment) fragment.add_frag_resources(child_fragment)
child_content += child_fragment.content child_content += child_fragment.content
......
<vertical_demo> <vertical_demo>
<html> <html_demo>
<p>Below are two mentoring blocks and a grade export block that <p>Below are two mentoring blocks and a grade export block that
should be able to export their data as CSV.</p> should be able to export their data as CSV.</p>
</html> </html_demo>
<mentoring display_name="Mentoring Block 1" mode="standard"> <mentoring display_name="Mentoring Block 1" mode="standard">
<html_demo> <html_demo>
<p>Please answer the question below.</p> <p>Please answer the question below.</p>
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
</mrq> </mrq>
<message type="completed"> <message type="completed">
<html><p>Congratulations!</p></html> <p>Congratulations!</p>
</message> </message>
<message type="incomplete"> <message type="incomplete">
<html><p>Still some work to do...</p></html> <p>Still some work to do...</p>
</message> </message>
</mentoring> </mentoring>
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
</mrq> </mrq>
<message type="completed"> <message type="completed">
<html><p>Congratulations!</p></html> <p>Congratulations!</p>
</message> </message>
<message type="incomplete"> <message type="incomplete">
<html><p>Still some work to do...</p></html> <p>Still some work to do...</p>
</message> </message>
</mentoring> </mentoring>
<vertical_demo> <vertical_demo>
<mentoring url_name="answer_edit_1" enforce_dependency="false"> <mentoring url_name="answer_edit_1" enforce_dependency="false">
<html> <html_demo>
<p>This should be displayed in the answer_edit scenario</p> <p>This should be displayed in the answer_edit scenario</p>
</html> </html_demo>
<answer name="answer_1" /> <answer name="answer_1" />
</mentoring> </mentoring>
......
<vertical_demo> <vertical_demo>
<html> <html_demo>
<p>Below are two mentoring blocks and a grade export block that <p>Below are two mentoring blocks and a grade export block that
should be able to export their data as CSV.</p> should be able to export their data as CSV.</p>
</html> </html_demo>
<mentoring display_name="Mentoring Block 1" mode="standard"> <mentoring display_name="Mentoring Block 1" mode="standard">
<title>Mentoring Block 1</title> <html_demo>
<html>
<p>Please answer the question below.</p> <p>Please answer the question below.</p>
</html> </html_demo>
<answer name="goal"> <answer name="goal">
<question>What is your goal?</question> <question>What is your goal?</question>
......
...@@ -47,7 +47,6 @@ BLOCKS = [ ...@@ -47,7 +47,6 @@ BLOCKS = [
'mentoring-dataexport = mentoring:MentoringDataExportBlock', 'mentoring-dataexport = mentoring:MentoringDataExportBlock',
'mentoring-table = mentoring.components:MentoringTableBlock', 'mentoring-table = mentoring.components:MentoringTableBlock',
'html = mentoring.components:HTMLBlock',
'mentoring-column = mentoring.components:MentoringTableColumn', 'mentoring-column = mentoring.components:MentoringTableColumn',
'mentoring-answer = mentoring.components:AnswerBlock', 'mentoring-answer = mentoring.components:AnswerBlock',
'mentoring-answer-recap = mentoring.components:AnswerRecapBlock', 'mentoring-answer-recap = mentoring.components:AnswerRecapBlock',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment