Don't delete question p-tag if children.
TNL-5510
This commit is contained in:
@@ -951,7 +951,13 @@ class LoncapaProblem(object):
|
||||
|
||||
if p_tag and p_tag[0].text == inputfields[0].attrib['label']:
|
||||
label = p_tag[0].text
|
||||
element_to_be_deleted = p_tag[0]
|
||||
|
||||
p_tag_children = list(p_tag[0])
|
||||
if len(p_tag_children) == 0:
|
||||
element_to_be_deleted = p_tag[0]
|
||||
else:
|
||||
# Delete the text from the p-tag, but leave the children.
|
||||
p_tag[0].text = ''
|
||||
else:
|
||||
# In this case the problems don't have tag or label attribute inside the responsetype
|
||||
# so we will get the first preceding label tag w.r.t to this responsetype.
|
||||
|
||||
@@ -424,6 +424,39 @@ class CAPAProblemTest(unittest.TestCase):
|
||||
self.assert_question_tag(question1, question2, tag='label', label_attr=False)
|
||||
self.assert_question_tag(question1, question2, tag='p', label_attr=True)
|
||||
|
||||
def test_question_tag_child_left(self):
|
||||
"""
|
||||
If the "old" question tag has children, don't delete the children when
|
||||
transforming to the new label tag.
|
||||
"""
|
||||
xml = """
|
||||
<problem>
|
||||
<p>Question<img src='img/src'/></p>
|
||||
<choiceresponse>
|
||||
<checkboxgroup label="Question">
|
||||
<choice correct="true">choice1</choice>
|
||||
<choice correct="false">choice2</choice>
|
||||
</checkboxgroup>
|
||||
</choiceresponse>
|
||||
</problem>
|
||||
"""
|
||||
|
||||
problem = new_loncapa_problem(xml)
|
||||
self.assertEqual(
|
||||
problem.problem_data,
|
||||
{
|
||||
'1_2_1':
|
||||
{
|
||||
'label': "Question",
|
||||
'descriptions': {}
|
||||
}
|
||||
}
|
||||
)
|
||||
# img tag is still present within the paragraph, but p text has been deleted
|
||||
self.assertEqual(len(problem.tree.xpath('//p')), 1)
|
||||
self.assertEqual(problem.tree.xpath('//p')[0].text, '')
|
||||
self.assertEqual(len(problem.tree.xpath('//p/img')), 1)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class CAPAMultiInputProblemTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user