Commit 8582e036 by Braden MacDonald

Allow hiding the title of the whole problem builder block

parent e9e5f81f
......@@ -121,6 +121,12 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
scope=Scope.content,
multiline_editor=True
)
show_title = Boolean(
display_name=_("Show title"),
help=_("Display the title?"),
default=True,
scope=Scope.content
)
# Settings
weight = Float(
......@@ -281,6 +287,7 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
fragment.add_content(loader.render_template('templates/html/mentoring.html', {
'self': self,
'title': self.display_name,
'show_title': self.show_title,
'child_content': child_content,
'missing_dependency_url': self.has_missing_dependency and self.next_step_url,
}))
......
......@@ -9,9 +9,9 @@
{% endwith %}
</div>
{% if title %}
{% if show_title and title %}
<div class="title">
{% if title %} <h2>{{ title }}</h2> {% endif %}
<h2>{{ title }}</h2>
</div>
{% endif %}
......
......@@ -22,6 +22,7 @@ Test that the various title/display_name options for Answer and MCQ/MRQ/Ratings
"""
# Imports ###########################################################
import ddt
from mock import patch
from xblockutils.base_test import SeleniumXBlockTest
......@@ -29,6 +30,32 @@ from xblockutils.base_test import SeleniumXBlockTest
# Classes ###########################################################
@ddt.ddt
class TitleTest(SeleniumXBlockTest):
"""
Test the various display_name/show_title options for Problem Builder
"""
@ddt.data(
('<problem-builder show_title="false"><pb-answer name="a"/></problem-builder>', None),
('<problem-builder><pb-answer name="a"/></problem-builder>', "Mentoring Questions"),
('<problem-builder mode="assessment"><pb-answer name="a"/></problem-builder>', "Mentoring Questions"),
('<problem-builder display_name="A Question"><pb-answer name="a"/></problem-builder>', "A Question"),
('<problem-builder display_name="A Question" show_title="false"><pb-answer name="a"/></problem-builder>', None),
)
@ddt.unpack
def test_title(self, xml, expected_title):
self.set_scenario_xml(xml)
pb_element = self.go_to_view()
if expected_title is not None:
h2 = pb_element.find_element_by_css_selector('h2')
self.assertEqual(h2.text, expected_title)
else:
# No <h2> element should be present:
all_h2s = pb_element.find_elements_by_css_selector('h2')
self.assertEqual(len(all_h2s), 0)
class StepTitlesTest(SeleniumXBlockTest):
"""
Test that the various title/display_name options for Answer and MCQ/MRQ/Ratings work.
......
<problem-builder enforce_dependency="false" followed_by="past_attempts">
<problem-builder enforce_dependency="false" followed_by="past_attempts" show_title="false">
<html>
<h3>Checking your improvement frog</h3>
<p>Now, let's make sure your frog meets the criteria for a strong column 1. Here is your frog:</p>
......
<problem-builder display_submit="false" enforce_dependency="false">
<problem-builder display_submit="false" enforce_dependency="false" display_name="Table">
<pb-table type="table_test" url_name="table_2">
<pb-column header="Header Test 1">
<pb-answer-recap name="table_1_answer_1" />
......
......@@ -6,6 +6,7 @@ This contains a table to test migration of tables from v1 schema to v2.
<option:xml_content>
<![CDATA[
<mentoring display_submit="false" enforce_dependency="false">
<title>Table</title>
<mentoring-table type="table_test" url_name="table_2">
<column>
<header>Header Test 1</header>
......
<problem-builder url_name="some_url_name" weight="1" mode="assessment" max_attempts="2">
<problem-builder url_name="some_url_name" weight="1" mode="assessment" max_attempts="2" show_title="false">
<pb-mcq name="M1" question="&lt;span&gt;&lt;i&gt;Review the following information. Then select the best answer and click &lt;b&gt;Submit.&lt;/b&gt; Click &lt;strong&gt;Next Question&lt;/strong&gt; to proceed.&lt;/i&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;If all elephants eat porridge, and some porridge is blue, do all elephants eat blue porridge?">
<pb-choice value="y">Yes</pb-choice>
<pb-choice value="n">No</pb-choice>
......
......@@ -66,8 +66,20 @@ class PrefixTags(Change):
self.node.tag = "pb-" + self.node.tag
class HideTitle(Change):
"""
If no <title> element is present, set hide_title="true"
"""
@staticmethod
def applies_to(node):
return node.tag == "problem-builder" and node.find("title") is None
def apply(self):
self.node.attrib["show_title"] = "false"
class RemoveTitle(Change):
""" The old <title> element is now an attribute of <mentoring> """
""" The old <title> element is now an attribute of <problem-builder> """
@staticmethod
def applies_to(node):
return node.tag == "title" and node.getparent().tag == "problem-builder"
......@@ -368,6 +380,7 @@ class CommaSeparatedListToJson(Change):
xml_changes = (
RenameMentoringTag,
PrefixTags,
HideTitle,
RemoveTitle,
UnwrapHTML,
RenameTableTag,
......
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