From 890588e9def394b9f29d8673fb6fbb6eebc45c61 Mon Sep 17 00:00:00 2001 From: Nick Parlante Date: Wed, 8 Oct 2014 16:03:06 -0700 Subject: [PATCH] Extended hints, squashed down --- CHANGELOG.rst | 2 + common/lib/capa/capa/capa_problem.py | 44 + common/lib/capa/capa/inputtypes.py | 18 +- common/lib/capa/capa/responsetypes.py | 328 +++++++- .../capa/capa/tests/response_xml_factory.py | 10 +- .../capa/tests/test_files/extended_hints.xml | 50 ++ .../test_files/extended_hints_checkbox.xml | 108 +++ .../test_files/extended_hints_dropdown.xml | 30 + .../extended_hints_multiple_choice.xml | 34 + .../extended_hints_numeric_input.xml | 37 + .../test_files/extended_hints_text_input.xml | 78 ++ .../test_files/extended_hints_with_errors.xml | 13 + .../capa/tests/test_hint_functionality.py | 297 +++++++ .../lib/capa/capa/tests/test_responsetypes.py | 6 + common/lib/xmodule/xmodule/capa_base.py | 64 +- common/lib/xmodule/xmodule/capa_module.py | 2 + .../lib/xmodule/xmodule/css/capa/display.scss | 18 +- .../xmodule/js/spec/problem/edit_spec.coffee | 12 +- .../js/spec/problem/edit_spec_hint.coffee | 772 ++++++++++++++++++ .../xmodule/js/src/capa/display.coffee | 19 + .../xmodule/js/src/problem/edit.coffee | 247 ++++-- .../problem/checkboxes_response.yaml | 43 +- .../templates/problem/multiplechoice.yaml | 28 +- .../templates/problem/numericalresponse.yaml | 9 +- .../templates/problem/optionresponse.yaml | 63 +- .../templates/problem/string_response.yaml | 28 +- .../xmodule/xmodule/tests/test_capa_module.py | 66 +- lms/templates/problem.html | 7 +- 28 files changed, 2275 insertions(+), 158 deletions(-) create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_checkbox.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_dropdown.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_multiple_choice.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_numeric_input.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_text_input.xml create mode 100644 common/lib/capa/capa/tests/test_files/extended_hints_with_errors.xml create mode 100644 common/lib/capa/capa/tests/test_hint_functionality.py create mode 100644 common/lib/xmodule/xmodule/js/spec/problem/edit_spec_hint.coffee diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 06fa45818e8d..b2df3a650858 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,6 +23,8 @@ LMS: Support adding students to a cohort via the instructor dashboard. TNL-163 LMS: Show cohorts on the new instructor dashboard. TNL-161 +LMS: Extended hints feature + LMS: Mobile API available for courses that opt in using the Course Advanced Setting "Mobile Course Available" (only used in limited closed beta). diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 699db9aaf35e..37faf54f1a58 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -162,6 +162,8 @@ def __init__(self, problem_text, id, capa_system, state=None, seed=None): # parse problem XML file into an element tree self.tree = etree.XML(problem_text) + self.make_xml_compatible(self.tree) + # handle any tags self._process_includes() @@ -191,6 +193,48 @@ def __init__(self, problem_text, id, capa_system, state=None, seed=None): self.extracted_tree = self._extract_html(self.tree) + def make_xml_compatible(self, tree): + """ + Adjust tree xml in-place for compatibility, such as + supporting an old xml format by translating it to a new format. + """ + # compatibility translation: + # old: ANSWER + # convert to + # new: OPTIONAL-HINT + # the new format is the form used at runtime and by this conversion we support + # the old format + additionals = tree.xpath('//stringresponse/additional_answer') + for additional in additionals: + answer = additional.get('answer') + text = additional.text + if not answer and text: # trigger of old->new conversion + additional.set('answer', text) + additional.text = '' + + # compatibility translation: + # optioninput uses option= like this: + # + # With extended hints there is a new + # This translation takes in the new format and synthesizes the old option= attribute + # so all downstream logic works unchanged with the new