diff --git a/cms/envs/common.py b/cms/envs/common.py index d4fb098f6f..7a2a3343a8 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -319,6 +319,7 @@ MAKO_TEMPLATE_DIRS_BASE = [ OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates', OPENEDX_ROOT / 'core' / 'lib' / 'license' / 'templates', CMS_ROOT / 'djangoapps' / 'pipeline_js' / 'templates', + XMODULE_ROOT / 'capa' / 'templates', ] CONTEXT_PROCESSORS = ( diff --git a/lms/templates/problem.html b/lms/templates/problem.html deleted file mode 100644 index e239c32cd2..0000000000 --- a/lms/templates/problem.html +++ /dev/null @@ -1,169 +0,0 @@ -<%page expression_filter="h"/> -<%! -from django.utils.translation import ngettext, gettext as _ -from openedx.core.djangolib.markup import HTML, Text -%> - -<%namespace name='static' file='static_content.html'/> -

- ${ problem['name'] } -

- -
- -
- ${ HTML(problem['html']) } -
- - % if demand_hint_possible: -
- <%include file="problem_notifications.html" args=" - notification_name='hint', - notification_type='problem-hint', - notification_icon='fa-question', - notification_message=''" - /> -
- % endif - -
- % if demand_hint_possible: - - - - % endif - % if save_button: - - - - % endif - % if attempts_used and reset_button: - - - - % endif - % if answer_available: - - - - % endif -
-
- - - % if submit_disabled_cta: - % if submit_disabled_cta.get('event_data'): - - - - - (${submit_disabled_cta['description']}) - % else: -
- % if submit_disabled_cta.get('link'): - - % for form_name, form_value in submit_disabled_cta['form_values'].items(): - - % endfor - - % endif - - - - (${submit_disabled_cta['description']}) -
- % endif - % endif -
- ## When attempts are not 0, the CTA above will contain a message about the number of used attempts - % if attempts_allowed and (not submit_disabled_cta or attempts_used == 0): - ${ngettext("You have used {num_used} of {num_total} attempt", "You have used {num_used} of {num_total} attempts", attempts_allowed).format(num_used=attempts_used, num_total=attempts_allowed)} - % endif - % if grading_method: -
${Text(_("Grading method: {grading_method}")).format(grading_method=grading_method)}
- % endif - ${_("Some problems have options such as save, reset, hints, or show answer. These options follow the Submit button.")} -
-
-
- <%include file="problem_notifications.html" args=" - notification_type='warning', - notification_icon='fa-exclamation-circle', - notification_name='gentle-alert', - notification_message=''" - /> - % if answer_notification_type: - % if 'correct' == answer_notification_type: - <%include file="problem_notifications.html" args=" - notification_type='success', - notification_icon='fa-check', - notification_name='submit', - is_hidden=False, - notification_message=answer_notification_message" - /> - % endif - % if 'incorrect' == answer_notification_type: - <%include file="problem_notifications.html" args=" - notification_type='error', - notification_icon='fa-close', - notification_name='submit', - is_hidden=False, - notification_message=answer_notification_message" - /> - % endif - % if 'partially-correct' == answer_notification_type: - <%include file="problem_notifications.html" args=" - notification_type='success', - notification_icon='fa-asterisk', - notification_name='submit', - is_hidden=False, - notification_message=answer_notification_message" - /> - % endif - % if 'submitted' == answer_notification_type: - <%include file="problem_notifications.html" args=" - notification_type='general', - notification_icon='fa-info-circle', - notification_name='submit', - is_hidden=False, - notification_message=answer_notification_message" - /> - % endif - % endif - <%include file="problem_notifications.html" args=" - notification_type='warning', - notification_icon='fa-save', - notification_name='save', - notification_message=save_message, - is_hidden=not has_saved_answers" - /> - <% - notification_message=_('Answers are displayed within the problem') - %> - <%include file="problem_notifications.html" args=" - notification_type='general', - notification_icon='fa-info-circle', - notification_name='show-answer', - notification_message=notification_message, - is_hidden=True" - /> -
- - diff --git a/lms/templates/problem_ajax.html b/lms/templates/problem_ajax.html deleted file mode 100644 index 6c0a60795e..0000000000 --- a/lms/templates/problem_ajax.html +++ /dev/null @@ -1,13 +0,0 @@ -
-

- - Loading… -

-
diff --git a/lms/templates/problem_notifications.html b/lms/templates/problem_notifications.html deleted file mode 100644 index 7b44387f19..0000000000 --- a/lms/templates/problem_notifications.html +++ /dev/null @@ -1,19 +0,0 @@ -<%page expression_filter="h" args="notification_name, notification_type, notification_icon, - notification_message, should_enable_next_hint, is_hidden=True"/> -<%! from django.utils.translation import gettext as _ %> - - diff --git a/scripts/xsslint/xsslint/linters.py b/scripts/xsslint/xsslint/linters.py index 911c50a34f..541abd5811 100644 --- a/scripts/xsslint/xsslint/linters.py +++ b/scripts/xsslint/xsslint/linters.py @@ -1476,6 +1476,7 @@ class DjangoTemplateLinter(BaseLinter): django_trans_missing_escape='django-trans-missing-escape', django_trans_invalid_escape_filter='django-trans-invalid-escape-filter', django_trans_escape_variable_mismatch='django-trans-escape-variable-mismatch', + django_trans_escape_filter_parse_error='django-trans-escape-filter-parse-error', django_blocktrans_missing_escape_filter='django-blocktrans-missing-escape-filter', django_blocktrans_parse_error='django-blocktrans-parse-error', django_blocktrans_escape_filter_parse_error='django-blocktrans-escape-filter-parse-error', diff --git a/scripts/xsslint_thresholds.json b/scripts/xsslint_thresholds.json index 97e4a1b60f..bbcf45f90f 100644 --- a/scripts/xsslint_thresholds.json +++ b/scripts/xsslint_thresholds.json @@ -8,6 +8,7 @@ "django-html-interpolation-missing-safe-filter": 0, "django-trans-escape-variable-mismatch": 0, "django-trans-invalid-escape-filter": 0, + "django-trans-escape-filter-parse-error": 0, "django-trans-missing-escape": 0, "javascript-concat-html": 2, "javascript-escape": 1, diff --git a/xmodule/capa/checker.py b/xmodule/capa/checker.py index 1a128cf98e..b5cdd5b814 100755 --- a/xmodule/capa/checker.py +++ b/xmodule/capa/checker.py @@ -10,8 +10,7 @@ import sys from io import BytesIO from calc import UndefinedVariable -from mako.lookup import TemplateLookup -from path import Path as path +from django.template.loader import get_template from xmodule.capa.capa_problem import LoncapaProblem @@ -21,14 +20,13 @@ log = logging.getLogger("capa.checker") class DemoSystem(object): # lint-amnesty, pylint: disable=missing-class-docstring def __init__(self): - self.lookup = TemplateLookup(directories=[path(__file__).dirname() / "templates"]) self.DEBUG = True def render_template(self, template_filename, dictionary): """ Render the specified template with the given dictionary of context data. """ - return self.lookup.get_template(template_filename).render(**dictionary) + return get_template(template_filename).render(dictionary) def main(): # lint-amnesty, pylint: disable=missing-function-docstring diff --git a/xmodule/capa/inputtypes.py b/xmodule/capa/inputtypes.py index 78b0dfb5b4..e85cb1a25b 100644 --- a/xmodule/capa/inputtypes.py +++ b/xmodule/capa/inputtypes.py @@ -18,7 +18,7 @@ Module containing the problem elements which render into input objects - formulaequationinput - chemicalequationinput -These are matched by *.html files templates/*.html which are mako templates with the +These are matched by *.html files templates/*.html which are django templates with the actual html. Each input type takes the xml tree as 'element', the previous answer as 'value', and the diff --git a/xmodule/capa/templates/annotationinput.html b/xmodule/capa/templates/annotationinput.html index e9940badd3..b2f2bad67e 100644 --- a/xmodule/capa/templates/annotationinput.html +++ b/xmodule/capa/templates/annotationinput.html @@ -1,62 +1,62 @@ -<%! from openedx.core.djangolib.markup import HTML %> +{% load static %}
-
+
- ${title} + {{ title|safe }} - % if return_to_annotation: + {% if return_to_annotation %} Return to Annotation
- % endif + {% endif %}
-
${text}
-
${comment}
+
{{ text|safe }}
+
{{ comment|safe }}
-
${comment_prompt}
- +
{{ comment_prompt|safe }}
+ -
${tag_prompt}
+
{{ tag_prompt|safe }}
    - % for option in options: + {% for option in options %}
  • - % if has_options_value: - % if all(c == status.classname for c in (option['choice'], status)): - - <%include file="status_span.html" args="status=status"/> + {% if has_options_value %} + {% if option.choice == status.classname and status == status.classname %} + + {% include "status_span.html" with status=status %} - % endif - % endif + {% endif %} + {% endif %} - ${option['description']} + {% endif %} + " data-id="{{ option.id }}"> + {{ option.description|safe }}
  • - % endfor + {% endfor %}
- % if debug: + {% if debug %}
Rendered with value:
-
${value|h}
+
{{ value|safe }}
Current input value:
- +
- % else: - - % endif + {% else %} + + {% endif %} - <%include file="status_span.html" args="status=status, status_id=id"/> + {% include "status_span.html" with status=status status_id=id %} -

+

-% if msg: -${HTML(msg)} -% endif +{% if msg %} +{{ msg|safe }} +{% endif %} diff --git a/xmodule/capa/templates/chemicalequationinput.html b/xmodule/capa/templates/chemicalequationinput.html index ca01d3d7c2..49145e1ddd 100644 --- a/xmodule/capa/templates/chemicalequationinput.html +++ b/xmodule/capa/templates/chemicalequationinput.html @@ -1,22 +1,21 @@ -<%! from xmodule.capa.util import remove_markup %> -
-
+
+
-
+
-

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

-
-

+
+

diff --git a/xmodule/capa/templates/choicegroup.html b/xmodule/capa/templates/choicegroup.html index 3b7350039f..7922c08a09 100644 --- a/xmodule/capa/templates/choicegroup.html +++ b/xmodule/capa/templates/choicegroup.html @@ -1,64 +1,46 @@ -<%page expression_filter="h"/> -<%! -from openedx.core.djangolib.markup import HTML -%> -<% - def is_radio_input(choice_id): - return input_type == 'radio' and ((isinstance(value, str) and (choice_id == value)) or ( - not isinstance(value, str) and choice_id in value - )) -%> -
-
- % if response_data['label']: - ${response_data['label']} - % endif - % for description_id, description_text in response_data['descriptions'].items(): -

${description_text}

- % endfor - % for choice_id, choice_label in choices: - <% - label_class = 'response-label field-label label-inline' - input_class = 'field-input input-' + input_type - input_checked = '' - - if is_radio_input(choice_id) or (input_type != 'radio' and choice_id in value): - input_class += ' submitted' - if status.classname and not show_correctness == 'never': - label_class += ' choicegroup_' + status.classname - %> +
+
+ {% if response_data.label %} + {{ response_data.label }} + {% endif %} + {% for description_id, description_text in response_data.descriptions.items %} +

{{ description_text|safe }}

+ {% endfor %} + {% for choice_id, choice_label in choices %}
-
- % endfor - + {% endfor %} +
- % 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 + {% if show_correctness != 'never' %} + {% include "status_span.html" with status=status status_id=id %} + {% else %} + {% include "status_span.html" with status=status status_id=id hide_correctness=True %} + {% endif %}
- % if show_correctness == "never" and (value or status not in ['unsubmitted']): -
${submitted_message}
- %endif - % if msg: - ${HTML(msg)} - % endif + {% if show_correctness == "never" %} + {% if value or status != "unsubmitted" %} +
{{ submitted_message|safe }}
+ {% endif %} + {% endif %} + {% if msg %} + {{ msg|safe }} + {% endif %}
diff --git a/xmodule/capa/templates/choicetext.html b/xmodule/capa/templates/choicetext.html index 544a30ac6a..ebaa2689f2 100644 --- a/xmodule/capa/templates/choicetext.html +++ b/xmodule/capa/templates/choicetext.html @@ -1,70 +1,72 @@ -<%! from xmodule.capa.util import remove_markup -from django.utils.translation import gettext as _ -from openedx.core.djangolib.markup import HTML -%> +{% load i18n %} +{% load static %} -<% element_checked = False %> -% for choice_id, _ in choices: - <% choice_id = choice_id %> - %if choice_id in value: - <% element_checked = True %> - %endif -% endfor -
-
-
+{% with element_checked=False %} +{% for choice_id, _ in choices %} + {% if choice_id in value %} + {% with element_checked=True %} + {% endwith %} + {% endif %} +{% endfor %} +
+
+
-
- % for choice_id, choice_description in choices: - <% choice_id = choice_id %> -
+ {% for choice_id, choice_description in choices %} +
- - % for content_node in choice_description: - % if content_node['type'] == 'text': + {% for content_node in choice_description %} + {% if content_node.type == 'text' %} - ${content_node['contents']} + {{ content_node.contents }} - % else: - <% my_id = content_node.get('contents','') %> - <% my_val = value.get(my_id,'') %> - - %endif + {% else %} + {% with my_id=content_node.contents|default:'' %} + {% with my_val=value.my_id|default:'' %} + + {% endwith %} + {% endwith %} + {% endif %} - ${content_node['tail_text']} + {{ content_node.tail_text }} - % endfor -

+ {% endfor %} +

- % endfor - + {% endfor %} +
- +
- % if input_type == 'checkbox' or not element_checked: - <%include file="status_span.html" args="status=status, status_id=id"/> - % endif + {% if input_type == 'checkbox' or not value or status.classname == 'incomplete' or status.classname == 'unsubmitted' or status.classname == 'unanswered' %} + {% include "status_span.html" with status=status status_id=id %} + {% endif %}
- % if show_correctness == "never" and (value or status not in ['unsubmitted']): -
${_(submitted_message)}
- %endif - % if msg: - ${HTML(msg)} - % endif + {% if show_correctness == "never" %} + {% if value or status != "unsubmitted" %} +
{{ submitted_message }}
+ {% endif %} + {% endif %} + {% if msg %} + {{ msg|safe }} + {% endif %}
+{% endwith %} diff --git a/xmodule/capa/templates/clarification.html b/xmodule/capa/templates/clarification.html index c7aa68a253..79893cb73c 100644 --- a/xmodule/capa/templates/clarification.html +++ b/xmodule/capa/templates/clarification.html @@ -1,5 +1,5 @@ - - (${clarification}) + ({{ clarification }}) diff --git a/xmodule/capa/templates/codeinput.html b/xmodule/capa/templates/codeinput.html index 6bb972756b..4f89ac77f6 100644 --- a/xmodule/capa/templates/codeinput.html +++ b/xmodule/capa/templates/codeinput.html @@ -1,50 +1,46 @@ -<%page expression_filter="h"/> -<%! -from django.utils.translation import gettext as _ -from openedx.core.djangolib.markup import HTML -%> -
- % if response_data['label']: - - % else: - - % endif - - - ${code_mirror_exit_message} + {% endif %} + >{{ value }} + + {{ code_mirror_exit_message }}
- <%include file="status_span.html" args="status=status, status_id=id"/> + {% include "status_span.html" with status=status status_id=id %} - % if status == 'queued': - - % endif + {% if status == 'queued' %} + + {% endif %} - % if hidden: -
- % endif + {% if hidden %} +
+ {% endif %} -

${status.display_name}

+

{{ status.display_name }}

- +
- ${HTML(msg)} + {{ msg|safe }}
diff --git a/xmodule/capa/templates/crystallography.html b/xmodule/capa/templates/crystallography.html index 4c8a03acd3..18599a1328 100644 --- a/xmodule/capa/templates/crystallography.html +++ b/xmodule/capa/templates/crystallography.html @@ -1,6 +1,5 @@ -<%! from openedx.core.djangolib.markup import HTML %> -
-
+
+
Lattice: @@ -10,21 +9,21 @@
- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %} - + - <%include file="status_span.html" args="status=status, status_id=id"/> + {% include "status_span.html" with status=status status_id=id %} -

+

- % if msg: - ${HTML(msg)} - % endif + {% if msg %} + {{ msg|safe }} + {% endif %} - % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %}
- % endif + {% endif %}
diff --git a/xmodule/capa/templates/designprotein2dinput.html b/xmodule/capa/templates/designprotein2dinput.html index 074ec1c594..46956ebe58 100644 --- a/xmodule/capa/templates/designprotein2dinput.html +++ b/xmodule/capa/templates/designprotein2dinput.html @@ -1,19 +1,19 @@ -
+
-
+
- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %}
- - + + - <%include file="status_span.html" args="status=status, status_id=id"/> + {% include "status_span.html" with status=status status_id=id %} -

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

+ {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %}
-% endif +{% endif %}
diff --git a/xmodule/capa/templates/drag_and_drop_input.html b/xmodule/capa/templates/drag_and_drop_input.html index 758968937e..e0b542f19d 100644 --- a/xmodule/capa/templates/drag_and_drop_input.html +++ b/xmodule/capa/templates/drag_and_drop_input.html @@ -1,34 +1,34 @@ -<%! from openedx.core.djangolib.markup import HTML %> -
-
+{% load static %} +
+
- + -
+
- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %} - -

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

+ {% include "status_span.html" with status=status status_id=id %}

-

+

- % if msg: - ${HTML(msg)} - % endif + {% if msg %} + {{ msg|safe }} + {% endif %} - % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %}
- % endif + {% endif %}
diff --git a/xmodule/capa/templates/editageneinput.html b/xmodule/capa/templates/editageneinput.html index ae211835e0..86799463e1 100644 --- a/xmodule/capa/templates/editageneinput.html +++ b/xmodule/capa/templates/editageneinput.html @@ -1,23 +1,23 @@ -
+
-
+
- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %}
- - - + + + -

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

+ {% include "status_span.html" with status=status status_id=id %}

-

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

+ {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %}
-% endif +{% endif %}
diff --git a/xmodule/capa/templates/editamolecule.html b/xmodule/capa/templates/editamolecule.html index b4db77ab0c..9a0aef5ee1 100644 --- a/xmodule/capa/templates/editamolecule.html +++ b/xmodule/capa/templates/editamolecule.html @@ -1,28 +1,28 @@ -
-
+
+
- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %} -
+

- + - + -

+

-

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

+ {% include "status_span.html" with status=status status_id=id %}

- % if status in ['unsubmitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: + {% if status == 'unsubmitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %}
- % endif + {% endif %}
diff --git a/xmodule/capa/templates/filesubmission.html b/xmodule/capa/templates/filesubmission.html index 1c1ac2b76a..2e0baebd06 100644 --- a/xmodule/capa/templates/filesubmission.html +++ b/xmodule/capa/templates/filesubmission.html @@ -1,14 +1,13 @@ -<%! from openedx.core.djangolib.markup import HTML %> -
+
- ${status.display_name} - % if status == 'queued': - - % endif -

${status}

+ {{ status.display_name }} + {% if status == 'queued' %} + + {% endif %} +

{{ status }}

- +
-
${HTML(msg)}
+
{{ msg|safe }}
diff --git a/xmodule/capa/templates/formulaequationinput.html b/xmodule/capa/templates/formulaequationinput.html index 798623f06e..e3d645f142 100644 --- a/xmodule/capa/templates/formulaequationinput.html +++ b/xmodule/capa/templates/formulaequationinput.html @@ -1,36 +1,34 @@ -<%page expression_filter="h"/> -<%! from openedx.core.djangolib.markup import HTML %> -<% doinline = 'style="display:inline-block;vertical-align:top"' if inline else "" %> -
-
- % if response_data['label']: - - % endif - % for description_id, description_text in response_data['descriptions'].items(): -

${description_text}

- % endfor - +
+ {% if response_data.label %} + + {% endif %} + {% for description_id, description_text in response_data.descriptions.items %} +

{{ description_text }}

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

+

-
+
\(\) - Loading + Loading
-
+
- % if msg: - ${HTML(msg)} - % endif + {% if msg %} + {{ msg|safe }} + {% endif %}
diff --git a/xmodule/capa/templates/imageinput.html b/xmodule/capa/templates/imageinput.html index 0d6c0d5f6b..77f82b243a 100644 --- a/xmodule/capa/templates/imageinput.html +++ b/xmodule/capa/templates/imageinput.html @@ -1,35 +1,35 @@ -<%page expression_filter="h"/> -
+{% load static %} +
Selection indicator
- (new ImageInput('${id | n, decode.utf8}')); + (new ImageInput('{{ id }}')); - <%include file="status_span.html" args="status=status, status_id=id"/> + {% include "status_span.html" with status=status status_id=id %}
diff --git a/xmodule/capa/templates/jsinput.html b/xmodule/capa/templates/jsinput.html index 17761d9d70..062eabecfe 100644 --- a/xmodule/capa/templates/jsinput.html +++ b/xmodule/capa/templates/jsinput.html @@ -1,59 +1,57 @@ -<%page expression_filter="h"/> -<%! from openedx.core.djangolib.markup import HTML %> -
-
-
- % if status in ['unsubmitted', 'submitted', 'correct', 'incorrect', 'partially-correct', 'incomplete']: -
- % endif +
+
+ {% if status == 'unsubmitted' or status == 'submitted' or status == 'correct' or status == 'incorrect' or status == 'partially-correct' or status == 'incomplete' %} +
+ {% endif %} -