From 6135323427929c899ea8f584824a6599ccdd4055 Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Wed, 27 Apr 2016 15:56:39 -0400 Subject: [PATCH 01/96] Load factory JS files with a synchronous + % endif From d9c798dca3e0b1695631d3802e0a761eca8ed8f6 Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Wed, 25 May 2016 16:20:10 -0400 Subject: [PATCH 02/96] Fix JS load order issues for edxnotes --- .../templates/static_content.html | 22 +++++++++++++++++++ common/templates/edxnotes_wrapper.html | 4 ++-- lms/templates/edxnotes/toggle_notes.html | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 5bf30b62dc..835c0f7997 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -90,6 +90,28 @@ source, template_path = Loader(engine).load_template_source(path) +<%def name="require_module_async(module_name, class_name)"> + + + <%def name="optional_include_mako(file, is_theming_enabled=False)"><% # http://stackoverflow.com/q/21219531 if is_theming_enabled: diff --git a/common/templates/edxnotes_wrapper.html b/common/templates/edxnotes_wrapper.html index 6742a7c152..fd9a4f07b2 100644 --- a/common/templates/edxnotes_wrapper.html +++ b/common/templates/edxnotes_wrapper.html @@ -11,7 +11,7 @@ from student.models import anonymous_id_for_user
${content}
-<%static:require_module module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory"> +<%static:require_module_async module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory"> var element = document.getElementById('edx-notes-wrapper-${uid}'); NotesVisibilityFactory.VisibilityDecorator.factory(element, ${json.dumps(params)}, ${edxnotes_visibility}); - + diff --git a/lms/templates/edxnotes/toggle_notes.html b/lms/templates/edxnotes/toggle_notes.html index f58adec8a5..90ef42b220 100644 --- a/lms/templates/edxnotes/toggle_notes.html +++ b/lms/templates/edxnotes/toggle_notes.html @@ -22,9 +22,9 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str -<%static:require_module module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory"> +<%static:require_module_async module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory"> NotesVisibilityFactory.ToggleVisibilityView( ${edxnotes_visibility | n, dump_js_escaped_json}, '${edxnotes_visibility_url | n, js_escaped_string}' ); - + From c281586a29ca0cfa25ba5861b79da677d349c642 Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Wed, 25 May 2016 16:43:29 -0400 Subject: [PATCH 03/96] Fix other usages of require_module outside <%block name="js-extra" --- lms/templates/courseware/accordion.html | 4 ++-- lms/templates/courseware/info.html | 8 ++++---- .../instructor/instructor_dashboard_2/certificates.html | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lms/templates/courseware/accordion.html b/lms/templates/courseware/accordion.html index bee38eab0c..b684299539 100644 --- a/lms/templates/courseware/accordion.html +++ b/lms/templates/courseware/accordion.html @@ -84,7 +84,7 @@ else: % if toc: - <%static:require_module module_name="js/courseware/accordion_events" class_name="AccordionEvents"> + <%static:require_module_async module_name="js/courseware/accordion_events" class_name="AccordionEvents"> AccordionEvents(); - + % endif diff --git a/lms/templates/courseware/info.html b/lms/templates/courseware/info.html index 93e479bb74..efa824d81f 100644 --- a/lms/templates/courseware/info.html +++ b/lms/templates/courseware/info.html @@ -38,12 +38,12 @@ from openedx.core.djangolib.markup import HTML, Text <%include file="/courseware/course_navigation.html" args="active_page='info'" /> -<%static:require_module module_name="js/courseware/toggle_element_visibility" class_name="ToggleElementVisibility"> +<%static:require_module_async module_name="js/courseware/toggle_element_visibility" class_name="ToggleElementVisibility"> ToggleElementVisibility(); - -<%static:require_module module_name="js/courseware/course_home_events" class_name="CourseHomeEvents"> + +<%static:require_module_async module_name="js/courseware/course_home_events" class_name="CourseHomeEvents"> CourseHomeEvents(); - + <%block name="js_extra"> ## CourseTalk widget js script diff --git a/lms/templates/instructor/instructor_dashboard_2/certificates.html b/lms/templates/instructor/instructor_dashboard_2/certificates.html index de2f969b70..f5d3bce534 100644 --- a/lms/templates/instructor/instructor_dashboard_2/certificates.html +++ b/lms/templates/instructor/instructor_dashboard_2/certificates.html @@ -6,13 +6,13 @@ from django.utils.translation import ugettext as _ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string %> -<%static:require_module module_name="js/certificates/factories/certificate_whitelist_factory" class_name="CertificateWhitelistFactory"> +<%static:require_module_async module_name="js/certificates/factories/certificate_whitelist_factory" class_name="CertificateWhitelistFactory"> CertificateWhitelistFactory(${certificate_white_list | n, dump_js_escaped_json}, '${generate_certificate_exceptions_url | n, js_escaped_string}', '${certificate_exception_view_url | n, js_escaped_string}', '${generate_bulk_certificate_exceptions_url | n, js_escaped_string}', ${bool(section_data['active_certificate']) | n, dump_js_escaped_json}); - + -<%static:require_module module_name="js/certificates/factories/certificate_invalidation_factory" class_name="CertificateInvalidationFactory"> +<%static:require_module_async module_name="js/certificates/factories/certificate_invalidation_factory" class_name="CertificateInvalidationFactory"> CertificateInvalidationFactory('${certificate_invalidations | n, dump_js_escaped_json}', '${certificate_invalidation_view_url | n, js_escaped_string}'); - +
From 2e4ad45bb0a0a1b14139f0034f86ab2d0ff0c9be Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Fri, 27 May 2016 16:08:06 -0400 Subject: [PATCH 04/96] Make require_module_async call require_module --- common/djangoapps/pipeline_mako/templates/static_content.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 835c0f7997..01d82a3710 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -94,9 +94,7 @@ source, template_path = Loader(engine).load_template_source(path) | # script tag end - <%static:require_module.*?> | # require js script tag start - | # require js script tag end + <%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version) + | # require js script tag end (optionally the _async version) <%block[ ]*name=['"]requirejs['"]\w*> | # require js tag start # require js tag end """, From 47bc8e65f3c4c6479c53704a35ac56f695af33a2 Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Tue, 31 May 2016 13:47:14 -0400 Subject: [PATCH 06/96] Fix actual safe template violations --- common/templates/edxnotes_wrapper.html | 14 ++++++++++---- .../instructor_dashboard_2/certificates.html | 9 +++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/templates/edxnotes_wrapper.html b/common/templates/edxnotes_wrapper.html index fd9a4f07b2..9ead26e911 100644 --- a/common/templates/edxnotes_wrapper.html +++ b/common/templates/edxnotes_wrapper.html @@ -1,17 +1,23 @@ +<%namespace name='static' file='/static_content.html'/> +<%page expression_filter="h"/> + <%! import json from django.utils.translation import ugettext as _ from student.models import anonymous_id_for_user +from openedx.core.djangolib.js_utils import js_escaped_string, dump_js_escaped_json %> -<%namespace name='static' file='/static_content.html'/> + <% if user: params.update({'user': anonymous_id_for_user(user, None)}) %> +
-
${content}
+
${content | n, decode.utf8 }
+ <%static:require_module_async module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory"> - var element = document.getElementById('edx-notes-wrapper-${uid}'); - NotesVisibilityFactory.VisibilityDecorator.factory(element, ${json.dumps(params)}, ${edxnotes_visibility}); + var element = document.getElementById('edx-notes-wrapper-${uid | n, js_escaped_string}'); + NotesVisibilityFactory.VisibilityDecorator.factory(element, ${params | n, dump_js_escaped_json}, ${edxnotes_visibility | n, decode.utf8}); diff --git a/lms/templates/instructor/instructor_dashboard_2/certificates.html b/lms/templates/instructor/instructor_dashboard_2/certificates.html index f5d3bce534..6d0c3507b0 100644 --- a/lms/templates/instructor/instructor_dashboard_2/certificates.html +++ b/lms/templates/instructor/instructor_dashboard_2/certificates.html @@ -4,14 +4,15 @@ <%! from django.utils.translation import ugettext as _ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string +from openedx.core.djangolib.markup import HTML %> <%static:require_module_async module_name="js/certificates/factories/certificate_whitelist_factory" class_name="CertificateWhitelistFactory"> - CertificateWhitelistFactory(${certificate_white_list | n, dump_js_escaped_json}, '${generate_certificate_exceptions_url | n, js_escaped_string}', '${certificate_exception_view_url | n, js_escaped_string}', '${generate_bulk_certificate_exceptions_url | n, js_escaped_string}', ${bool(section_data['active_certificate']) | n, dump_js_escaped_json}); + CertificateWhitelistFactory(${certificate_white_list | n, dump_js_escaped_json}, '${generate_certificate_exceptions_url | n, js_escaped_string}', '${certificate_exception_view_url | n, js_escaped_string}', '${generate_bulk_certificate_exceptions_url | n, js_escaped_string}', ${bool(section_data['active_certificate']) | n, dump_js_escaped_json}); <%static:require_module_async module_name="js/certificates/factories/certificate_invalidation_factory" class_name="CertificateInvalidationFactory"> - CertificateInvalidationFactory('${certificate_invalidations | n, dump_js_escaped_json}', '${certificate_invalidation_view_url | n, js_escaped_string}'); + CertificateInvalidationFactory('${certificate_invalidations | n, dump_js_escaped_json}', '${certificate_invalidation_view_url | n, js_escaped_string}');
@@ -85,7 +86,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str % else:

- ${_("When you are ready to generate certificates for your course, click Generate Certificates. You do not need to do this
if you have set the certificate mode to on-demand generation.")} + ${HTML(_("When you are ready to generate certificates for your course, click Generate Certificates. You do not need to do this
if you have set the certificate mode to on-demand generation."))}

%endif @@ -112,7 +113,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str

${_("Regenerate Certificates")}

- ${_('To regenerate certificates for your course, choose the learners who will receive regenerated certificates and click
Regenerate Certificates.')} + ${HTML(_('To regenerate certificates for your course, choose the learners who will receive regenerated certificates and click
Regenerate Certificates.'))}

- +
-

${_('Save changes')}

+

${_('Save changes')}

${_("You have unsaved changes.")}

@@ -74,12 +75,12 @@ from openedx.core.djangolib.js_utils import (
-

${_('Error')}

+

${_('Error')}

${_("There was an error saving changes.")}

-

${_('Schedule a Unit')}

+

${_('Schedule a Unit')}

diff --git a/lms/templates/ccx/student_admin.html b/lms/templates/ccx/student_admin.html index 369dad9ca2..0c3e5eb354 100644 --- a/lms/templates/ccx/student_admin.html +++ b/lms/templates/ccx/student_admin.html @@ -1,12 +1,7 @@ <%page expression_filter="h"/> <%! from django.utils.translation import ugettext as _ %> -
-

${_('Student Grades')}

-

- ${_('View gradebook')} -

-

- ${_('Download student grades')} -

-
+ +

${_('Student Grades')}

+

${_('View gradebook')}

+

${_('Download student grades')}

diff --git a/lms/templates/file-upload.underscore b/lms/templates/file-upload.underscore index bacbe60939..e5edabb373 100644 --- a/lms/templates/file-upload.underscore +++ b/lms/templates/file-upload.underscore @@ -1,9 +1,9 @@
-

<%- title %>

+

<%- title %>

- +
diff --git a/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html b/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html index 543498f29e..14760bd69b 100644 --- a/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html +++ b/lms/templates/instructor/instructor_dashboard_2/add_coupon_modal.html @@ -3,7 +3,8 @@ from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse %> -