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
13aed417
Commit
13aed417
authored
Apr 12, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1843 from MITx/feature/diana/textline-trailing
Add the ability to add trailing text to textlines
parents
734b169e
06a54a8c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
2 deletions
+57
-2
common/lib/capa/capa/inputtypes.py
+16
-2
common/lib/capa/capa/templates/textline.html
+1
-0
common/lib/capa/capa/tests/test_html_render.py
+1
-0
common/lib/capa/capa/tests/test_inputtypes.py
+39
-0
No files found.
common/lib/capa/capa/inputtypes.py
View file @
13aed417
...
...
@@ -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
):
...
...
common/lib/capa/capa/templates/textline.html
View file @
13aed417
...
...
@@ -31,6 +31,7 @@
style=
"display:none;"
%
endif
/>
${trailing_text | h}
<p
class=
"status"
>
% if status == 'unsubmitted':
...
...
common/lib/capa/capa/tests/test_html_render.py
View file @
13aed417
...
...
@@ -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'
}
...
...
common/lib/capa/capa/tests/test_inputtypes.py
View file @
13aed417
...
...
@@ -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
):
'''
...
...
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