Merge pull request #1843 from MITx/feature/diana/textline-trailing
Add the ability to add trailing text to textlines
This commit is contained in:
@@ -457,8 +457,21 @@ class TextLine(InputTypeBase):
|
||||
"""
|
||||
A text line input. Can do math preview if "math"="1" is specified.
|
||||
|
||||
If the hidden attribute is specified, the textline is hidden and the input id is stored in a div with name equal
|
||||
to the value of the hidden attribute. This is used e.g. for embedding simulations turned into questions.
|
||||
If "trailing_text" is set to a value, then the textline will be shown with
|
||||
the value after the text input, and before the checkmark or any input-specific
|
||||
feedback. HTML will not work, but properly escaped HTML characters will. This
|
||||
feature is useful if you would like to specify a specific type of units for the
|
||||
text input.
|
||||
|
||||
If the hidden attribute is specified, the textline is hidden and the input id
|
||||
is stored in a div with name equal to the value of the hidden attribute. This
|
||||
is used e.g. for embedding simulations turned into questions.
|
||||
|
||||
Example:
|
||||
<texline math="1" trailing_text="m/s" />
|
||||
|
||||
This example will render out a text line with a math preview and the text 'm/s'
|
||||
after the end of the text line.
|
||||
"""
|
||||
|
||||
template = "textline.html"
|
||||
@@ -483,6 +496,7 @@ class TextLine(InputTypeBase):
|
||||
Attribute('dojs', None, render=False),
|
||||
Attribute('preprocessorClassName', None, render=False),
|
||||
Attribute('preprocessorSrc', None, render=False),
|
||||
Attribute('trailing_text', ''),
|
||||
]
|
||||
|
||||
def setup(self):
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
style="display:none;"
|
||||
% endif
|
||||
/>
|
||||
${trailing_text | h}
|
||||
|
||||
<p class="status">
|
||||
% if status == 'unsubmitted':
|
||||
|
||||
@@ -156,6 +156,7 @@ class CapaHtmlRenderTest(unittest.TestCase):
|
||||
'hidden': False,
|
||||
'do_math': False,
|
||||
'id': '1_2_1',
|
||||
'trailing_text': '',
|
||||
'size': None}
|
||||
|
||||
expected_solution_context = {'id': '1_solution_1'}
|
||||
|
||||
@@ -182,6 +182,7 @@ class TextLineTest(unittest.TestCase):
|
||||
'hidden': False,
|
||||
'inline': False,
|
||||
'do_math': False,
|
||||
'trailing_text': '',
|
||||
'preprocessor': None}
|
||||
self.assertEqual(context, expected)
|
||||
|
||||
@@ -209,11 +210,49 @@ class TextLineTest(unittest.TestCase):
|
||||
'msg': '',
|
||||
'hidden': False,
|
||||
'inline': False,
|
||||
'trailing_text': '',
|
||||
'do_math': True,
|
||||
'preprocessor': {'class_name': preprocessorClass,
|
||||
'script_src': script}}
|
||||
self.assertEqual(context, expected)
|
||||
|
||||
def test_trailing_text_rendering(self):
|
||||
size = "42"
|
||||
# store (xml_text, expected)
|
||||
trailing_text = []
|
||||
# standard trailing text
|
||||
trailing_text.append(('m/s', 'm/s'))
|
||||
# unicode trailing text
|
||||
trailing_text.append((u'\xc3', u'\xc3'))
|
||||
# html escaped trailing text
|
||||
# this is the only one we expect to change
|
||||
trailing_text.append(('a < b','a < b'))
|
||||
|
||||
for xml_text, expected_text in trailing_text:
|
||||
xml_str = u"""<textline id="prob_1_2"
|
||||
size="{size}"
|
||||
trailing_text="{tt}"
|
||||
/>""".format(size=size, tt=xml_text)
|
||||
|
||||
element = etree.fromstring(xml_str)
|
||||
|
||||
state = {'value': 'BumbleBee', }
|
||||
the_input = lookup_tag('textline')(test_system, element, state)
|
||||
|
||||
context = the_input._get_render_context()
|
||||
|
||||
expected = {'id': 'prob_1_2',
|
||||
'value': 'BumbleBee',
|
||||
'status': 'unanswered',
|
||||
'size': size,
|
||||
'msg': '',
|
||||
'hidden': False,
|
||||
'inline': False,
|
||||
'do_math': False,
|
||||
'trailing_text': expected_text,
|
||||
'preprocessor': None}
|
||||
self.assertEqual(context, expected)
|
||||
|
||||
|
||||
class FileSubmissionTest(unittest.TestCase):
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user