Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
9ac8ef54
Commit
9ac8ef54
authored
Mar 01, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overall message HTMl now correctly renders when multiple HTML tags are
passed as the message (even when there's no root tag)
parent
952716af
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
17 deletions
+32
-17
common/lib/capa/capa/responsetypes.py
+24
-13
common/lib/capa/capa/tests/test_html_render.py
+8
-4
No files found.
common/lib/capa/capa/responsetypes.py
View file @
9ac8ef54
...
...
@@ -199,19 +199,7 @@ class LoncapaResponse(object):
# Add a <div> for the message at the end of the response
if
response_msg
:
response_msg_div
=
etree
.
SubElement
(
tree
,
'div'
)
response_msg_div
.
set
(
"class"
,
"response_message"
)
# If the response message can be represented as an XHTML tree,
# create the tree and append it to the message <div>
try
:
response_tree
=
etree
.
XML
(
response_msg
)
response_msg_div
.
append
(
response_tree
)
# Otherwise, assume that the message is text (not XHTML)
# and insert it as the text of the message <div>
except
:
response_msg_div
.
text
=
response_msg
tree
.
append
(
self
.
_render_response_msg_html
(
response_msg
))
return
tree
...
...
@@ -337,6 +325,29 @@ class LoncapaResponse(object):
def
__unicode__
(
self
):
return
u'LoncapaProblem Response
%
s'
%
self
.
xml
.
tag
def
_render_response_msg_html
(
self
,
response_msg
):
""" Render a <div> for a message that applies to the entire response.
*response_msg* is a string, which may contain XHTML markup
Returns an etree element representing the response message <div> """
# First try wrapping the text in a <div> and parsing
# it as an XHTML tree
try
:
response_msg_div
=
etree
.
XML
(
'<div>
%
s</div>'
%
str
(
response_msg
))
# If we can't do that, create the <div> and set the message
# as the text of the <div>
except
:
response_msg_div
=
etree
.
Element
(
'div'
)
response_msg_div
.
text
=
str
(
response_msg
)
# Set the css class of the message <div>
response_msg_div
.
set
(
"class"
,
"response_message"
)
return
response_msg_div
#-----------------------------------------------------------------------------
...
...
common/lib/capa/capa/tests/test_html_render.py
View file @
9ac8ef54
...
...
@@ -135,7 +135,8 @@ class CapaHtmlRenderTest(unittest.TestCase):
# CustomResponse script that sets an overall_message
script
=
textwrap
.
dedent
(
"""
def check_func(*args):
return {'overall_message': '<p>Test message</p>',
msg = '<p>Test message 1<br /></p><p>Test message 2</p>'
return {'overall_message': msg,
'input_list': [ {'ok': True, 'msg': '' } ] }
"""
)
...
...
@@ -160,9 +161,12 @@ class CapaHtmlRenderTest(unittest.TestCase):
self
.
assertEqual
(
msg_div_element
.
get
(
'class'
),
"response_message"
)
# Expect that the <div> contains our message (as part of the XML tree)
msg_p_element
=
msg_div_element
.
find
(
'p'
)
self
.
assertEqual
(
msg_p_element
.
tag
,
"p"
)
self
.
assertEqual
(
msg_p_element
.
text
,
"Test message"
)
msg_p_elements
=
msg_div_element
.
findall
(
'p'
)
self
.
assertEqual
(
msg_p_elements
[
0
]
.
tag
,
"p"
)
self
.
assertEqual
(
msg_p_elements
[
0
]
.
text
,
"Test message 1"
)
self
.
assertEqual
(
msg_p_elements
[
1
]
.
tag
,
"p"
)
self
.
assertEqual
(
msg_p_elements
[
1
]
.
text
,
"Test message 2"
)
def
test_substitute_python_vars
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment