Skip to content

Commit

Permalink
Allow html input to studio setting prompt box
Browse files Browse the repository at this point in the history
The safe tag is a 'djagno template pipeline'
builtin to escape html injected into the
template.
  • Loading branch information
caseylitton committed Jun 26, 2017
1 parent 2efa18a commit 540be40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion freetextresponse/templates/freetextresponse_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="freetextresponse xmodule_display xmodule_CapaModule problem">
<h2 class="problem-header">{{ display_name }}</h2>
<div class="problem-progress">{{ problem_progress }}</div>
<p>{{ prompt }}</p>
<p>{{ prompt|safe }}</p>
<div class="word-count-message">{{ word_count_message }}</div>
<div class="capa_inputtype textline">
<div class="user_input {{ indicator_class }}">
Expand Down
24 changes: 24 additions & 0 deletions freetextresponse/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from xblock.field_data import DictFieldData
from xblock.validation import ValidationMessage

from django.template.loader import get_template

from .freetextresponse import Credit
from .freetextresponse import FreeTextResponse

Expand Down Expand Up @@ -167,6 +169,28 @@ def test_student_view(self):
student_view_html
)

def test_build_fragment_prompt_html(self):
"""
Checks that build_fragment allows html in the prompt variable
if the 'safe' filter is not used then the django
template pipeline returns html tags like,
'&lt;p&gt;Please enter your response here&lt;/p&gt;'
"""
studio_settings_prompt = "<p>Please enter your response here</p>"
context = {
'prompt': studio_settings_prompt,
}
template = get_template('freetextresponse_view.html')
fragment = self.xblock.build_fragment(
template,
context,
initialize_js_func='FreeTextResponseView',
additional_css=[],
additional_js=[],
)
self.assertIn(studio_settings_prompt, fragment.content)

def test_max_score(self):
"""
Tests max_score function
Expand Down

0 comments on commit 540be40

Please sign in to comment.