diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 691eb558fb..9be71ade8f 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -39,25 +39,27 @@ graded status as'status' # makes sense, but a bunch of problems have markup that assumes block. Bigger TODO: figure out a # general css and layout strategy for capa, document it, then implement it. -import time import json import logging -from lxml import etree -import re import shlex # for splitting quoted strings import sys -import pyparsing -import html5lib -import bleach - -from .util import sanitize_html -from .registry import TagRegistry -from chem import chemcalc -from calc.preview import latex_preview -import xqueue_interface -from xqueue_interface import XQUEUE_TIMEOUT +import time from datetime import datetime + +import bleach +import html5lib +import pyparsing +import re +from calc.preview import latex_preview +from chem import chemcalc +from lxml import etree +from openedx.core.djangolib.markup import HTML, Text + +import xqueue_interface from xmodule.stringify import stringify_children +from capa.xqueue_interface import XQUEUE_TIMEOUT +from .registry import TagRegistry +from .util import sanitize_html log = logging.getLogger(__name__) @@ -232,7 +234,8 @@ class InputTypeBase(object): # put hint above msg if it should be displayed if self.hintmode == 'always': - self.msg = self.hint + ('
' if self.msg else '') + self.msg + self.msg = HTML('{hint}
{msg}' if self.msg else '{hint}').format(hint=HTML(self.hint), + msg=HTML(self.msg)) self.status = state.get('status', 'unanswered') @@ -322,15 +325,18 @@ class InputTypeBase(object): 'msg': self.msg, 'response_data': self.response_data, 'STATIC_URL': self.capa_system.STATIC_URL, - 'describedby_html': '', + 'describedby_html': HTML(''), } - # Don't add aria-describedby attribute if there are no descriptions - if self.response_data.get('descriptions'): - description_ids = ' '.join(self.response_data.get('descriptions').keys()) - context.update( - {'describedby_html': 'aria-describedby="{}"'.format(description_ids)} - ) + # Generate the list of ids to be used with the aria-describedby field. + # Every list should contain the status id + status_id = 'status_' + self.input_id + descriptions = list([status_id]) + descriptions.extend(self.response_data.get('descriptions', {}).keys()) + description_ids = ' '.join(descriptions) + context.update( + {'describedby_html': HTML('aria-describedby="{}"').format(description_ids)} + ) context.update( (a, v) for (a, v) in self.loaded_attributes.iteritems() if a in self.to_render @@ -522,9 +528,10 @@ class ChoiceGroup(InputTypeBase): choices.append((choice.get("name"), stringify_children(choice))) else: if choice.tag != 'compoundhint': - msg = u'[capa.inputtypes.extract_choices] {error_message}'.format( - # Translators: '' and '' are tag names and should not be translated. - error_message=_('Expected a or tag; got {given_tag} instead').format( + msg = Text('[capa.inputtypes.extract_choices] {error_message}').format( + error_message=Text( + # Translators: '' and '' are tag names and should not be translated. + _('Expected a or tag; got {given_tag} instead')).format( given_tag=choice.tag ) ) @@ -939,13 +946,13 @@ class MatlabInput(CodeInput): queue_msg = self.queue_msg if len(self.queue_msg) > 0: # An empty string cannot be parsed as XML but is okay to include in the template. try: - etree.XML(u'
{0}
'.format(self.queue_msg)) + etree.XML(HTML(u'
{0}
').format(HTML(self.queue_msg))) except etree.XMLSyntaxError: try: html5lib.parseFragment(self.queue_msg, treebuilder='lxml', namespaceHTMLElements=False)[0] except (IndexError, ValueError): # If neither can parse queue_msg, it contains invalid xml. - queue_msg = u"{0}".format(_("Error running code.")) + queue_msg = HTML("{0}").format(_("Error running code.")) extra_context = { 'queue_len': str(self.queue_len), @@ -1797,10 +1804,10 @@ class ChoiceTextGroup(InputTypeBase): for choice in element: if choice.tag != 'choice': - msg = u"[capa.inputtypes.extract_choices] {0}".format( + msg = Text("[capa.inputtypes.extract_choices] {0}").format( # Translators: a "tag" is an XML element, such as "" in HTML - _("Expected a {expected_tag} tag; got {given_tag} instead").format( - expected_tag=u"", + Text(_("Expected a {expected_tag} tag; got {given_tag} instead")).format( + expected_tag="", given_tag=choice.tag, ) ) diff --git a/common/lib/capa/capa/templates/annotationinput.html b/common/lib/capa/capa/templates/annotationinput.html index 02c434bd78..fd0f149e1a 100644 --- a/common/lib/capa/capa/templates/annotationinput.html +++ b/common/lib/capa/capa/templates/annotationinput.html @@ -22,12 +22,10 @@ % for option in options:
  • % if has_options_value: - % if all([c == 'correct' for c in option['choice'], status]): - Status: Correct - % elif all([c == 'partially-correct' for c in option['choice'], status]): - Status: Partially Correct - % elif all([c == 'incorrect' for c in option['choice'], status]): - Status: Incorrect + % if all([c == status.classname for c in option['choice'], status]): + + <%include file="status_span.html" args="status=status"/> + % endif % endif @@ -53,7 +51,7 @@ % endif - ${status.display_name} + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/chemicalequationinput.html b/common/lib/capa/capa/templates/chemicalequationinput.html index 6d25a31d6d..b61172951a 100644 --- a/common/lib/capa/capa/templates/chemicalequationinput.html +++ b/common/lib/capa/capa/templates/chemicalequationinput.html @@ -2,23 +2,21 @@
    -
    +
    - + -

    +

    ${value|h} - ${status.display_name} + <%include file="status_span.html" args="status=status, status_id=id"/>

    -

    - -% if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
    -% endif +

    +
    diff --git a/common/lib/capa/capa/templates/choicegroup.html b/common/lib/capa/capa/templates/choicegroup.html index 259ea37373..e5a16cdd45 100644 --- a/common/lib/capa/capa/templates/choicegroup.html +++ b/common/lib/capa/capa/templates/choicegroup.html @@ -7,7 +7,7 @@ )) %>
    -
    +
    % if response_data['label']: ${response_data['label']} % endif @@ -37,7 +37,7 @@ % endif % endif class="${label_class}" - ${HTML(describedby_html)} + ${describedby_html} > ${HTML(choice_label)} % if is_radio_input(choice_id): - % if status in ('correct', 'partially-correct', 'incorrect') and not show_correctness == 'never': - ${status.display_name} + % if not show_correctness == 'never' and status.classname != 'unanswered': + <%include file="status_span.html" args="status=status, status_id=id"/> % endif % endif @@ -59,10 +59,12 @@
    - % if input_type == 'checkbox' or not value: - - ${status.display_tooltip} - + % if input_type == 'checkbox' or status.classname == 'unanswered': + % if show_correctness != 'never': + <%include file="status_span.html" args="status=status, status_id=id"/> + % else: + <%include file="status_span.html" args="status=status, status_id=id, hide_correctness=True"/> + % endif % endif
    % if show_correctness == "never" and (value or status not in ['unsubmitted']): diff --git a/common/lib/capa/capa/templates/choicetext.html b/common/lib/capa/capa/templates/choicetext.html index 88422e6c1e..17cf41b7e9 100644 --- a/common/lib/capa/capa/templates/choicetext.html +++ b/common/lib/capa/capa/templates/choicetext.html @@ -66,9 +66,7 @@ from openedx.core.djangolib.markup import HTML
    % if input_type == 'checkbox' or not element_checked: - - ${status.display_name} - + <%include file="status_span.html" args="status=status, status_id=id"/> % endif
    diff --git a/common/lib/capa/capa/templates/codeinput.html b/common/lib/capa/capa/templates/codeinput.html index 57d4d82807..5ee8eb184c 100644 --- a/common/lib/capa/capa/templates/codeinput.html +++ b/common/lib/capa/capa/templates/codeinput.html @@ -26,12 +26,9 @@ from openedx.core.djangolib.markup import HTML
    - - ${status.display_name} - + + <%include file="status_span.html" args="status=status, status_id=id"/> + % if status == 'queued': % endif diff --git a/common/lib/capa/capa/templates/crystallography.html b/common/lib/capa/capa/templates/crystallography.html index 3229f75c10..4c8a03acd3 100644 --- a/common/lib/capa/capa/templates/crystallography.html +++ b/common/lib/capa/capa/templates/crystallography.html @@ -16,9 +16,7 @@ -

    - ${status.display_name} -

    + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/designprotein2dinput.html b/common/lib/capa/capa/templates/designprotein2dinput.html index 3cdce1c97a..074ec1c594 100644 --- a/common/lib/capa/capa/templates/designprotein2dinput.html +++ b/common/lib/capa/capa/templates/designprotein2dinput.html @@ -10,9 +10,7 @@ -

    - ${status.display_name} -

    + <%include file="status_span.html" args="status=status, status_id=id"/>

    % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: diff --git a/common/lib/capa/capa/templates/drag_and_drop_input.html b/common/lib/capa/capa/templates/drag_and_drop_input.html index b18d9ed1dd..a955453416 100644 --- a/common/lib/capa/capa/templates/drag_and_drop_input.html +++ b/common/lib/capa/capa/templates/drag_and_drop_input.html @@ -17,8 +17,9 @@ +

    - ${status.display_name} + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/editageneinput.html b/common/lib/capa/capa/templates/editageneinput.html index 4ae36cb964..c3dd75a3da 100644 --- a/common/lib/capa/capa/templates/editageneinput.html +++ b/common/lib/capa/capa/templates/editageneinput.html @@ -3,7 +3,7 @@
    % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
    +
    % endif
    @@ -12,7 +12,7 @@

    - ${status.display_name} + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/editamolecule.html b/common/lib/capa/capa/templates/editamolecule.html index 633bff4c05..83ca14a4f0 100644 --- a/common/lib/capa/capa/templates/editamolecule.html +++ b/common/lib/capa/capa/templates/editamolecule.html @@ -2,7 +2,7 @@
    % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
    +
    % endif
    @@ -17,7 +17,7 @@

    - ${status.display_name} + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/formulaequationinput.html b/common/lib/capa/capa/templates/formulaequationinput.html index 32839565d8..fe66dfa89a 100644 --- a/common/lib/capa/capa/templates/formulaequationinput.html +++ b/common/lib/capa/capa/templates/formulaequationinput.html @@ -2,7 +2,7 @@ <%! from openedx.core.djangolib.markup import HTML %> <% doinline = 'style="display:inline-block;vertical-align:top"' if inline else "" %>
    -
    +
    % if response_data['label']: % endif @@ -11,16 +11,14 @@ % endfor ${trailing_text} - - ${status.display_tooltip} - + <%include file="status_span.html" args="status=status, status_id=id"/>

    diff --git a/common/lib/capa/capa/templates/imageinput.html b/common/lib/capa/capa/templates/imageinput.html index e397c29743..ca9cfafce8 100644 --- a/common/lib/capa/capa/templates/imageinput.html +++ b/common/lib/capa/capa/templates/imageinput.html @@ -40,11 +40,5 @@ (new ImageInput('${id}')); - - ${status.display_name} - + <%include file="status_span.html" args="status=status, status_id=id"/>
    diff --git a/common/lib/capa/capa/templates/javascriptinput.html b/common/lib/capa/capa/templates/javascriptinput.html index b4d007e4d8..317c77a22c 100644 --- a/common/lib/capa/capa/templates/javascriptinput.html +++ b/common/lib/capa/capa/templates/javascriptinput.html @@ -1,8 +1,9 @@ +<%page expression_filter="h"/>
    + data-submission="${value}" data-evaluation="${msg}">
    diff --git a/common/lib/capa/capa/templates/jsinput.html b/common/lib/capa/capa/templates/jsinput.html index 6b42e83ef4..e1ee34f0a5 100644 --- a/common/lib/capa/capa/templates/jsinput.html +++ b/common/lib/capa/capa/templates/jsinput.html @@ -22,7 +22,7 @@
    % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
    +
    % endif