Refactor and improve js_utils helpers
- Rename escape_json_dumps to dump_js_escaped_json - Rename escape_js_string to js_escaped_string - Update js_escaped_string to output empty string for None - Introduce dump_html_escaped_json - Move dump_js_escaped_json after the pipe as new best practice - Introduce additional uses of helpers - Introduce new djangolib directory and move js_utils
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import (
|
||||
escape_json_dumps, escape_js_string
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<!doctype html>
|
||||
@@ -47,7 +47,7 @@ from openedx.core.lib.js_utils import (
|
||||
<a class="nav-skip" href="#content">${_("Skip to main content")}</a>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.baseUrl = "${escape_js_string(settings.STATIC_URL) | n}";
|
||||
window.baseUrl = "${settings.STATIC_URL | n, js_escaped_string}";
|
||||
var require = {baseUrl: window.baseUrl};
|
||||
</script>
|
||||
<script type="text/javascript" src="${static.url("js/vendor/require.js")}"></script>
|
||||
@@ -85,14 +85,14 @@ from openedx.core.lib.js_utils import (
|
||||
% if context_course:
|
||||
require(['js/factories/course'], function(CourseFactory) {
|
||||
CourseFactory({
|
||||
id: "${escape_js_string(context_course.id) | n}",
|
||||
id: "${context_course.id | n, js_escaped_string}",
|
||||
name: "${context_course.display_name_with_default_escaped | h}",
|
||||
url_name: "${context_course.location.name | h}",
|
||||
org: "${context_course.location.org | h}",
|
||||
num: "${context_course.location.course | h}",
|
||||
display_course_number: "${_(context_course.display_coursenumber) if context_course.display_coursenumber else ''}",
|
||||
display_course_number: "${context_course.display_coursenumber | n, js_escaped_string}",
|
||||
revision: "${context_course.location.revision | h}",
|
||||
self_paced: ${escape_json_dumps(context_course.self_paced) | n}
|
||||
self_paced: ${context_course.self_paced | n, dump_js_escaped_json}
|
||||
});
|
||||
});
|
||||
% endif
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
<%!
|
||||
from contentstore import utils
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
|
||||
<%block name="title">${_("Course Certificates")}</%block>
|
||||
@@ -29,11 +31,19 @@ CMS.User.isGlobalStaff = '${is_global_staff}'=='True' ? true : false;
|
||||
</%block>
|
||||
|
||||
<%block name="requirejs">
|
||||
% if has_certificate_modes:
|
||||
require(["js/certificates/factories/certificates_page_factory"], function(CertificatesPageFactory) {
|
||||
if(${escape_json_dumps(has_certificate_modes)}) {
|
||||
CertificatesPageFactory(${escape_json_dumps(certificates) | n}, "${certificate_url}", "${course_outline_url}", ${escape_json_dumps(course_modes) | n}, ${escape_json_dumps(certificate_web_view_url) | n}, ${escape_json_dumps(is_active) | n}, ${escape_json_dumps(certificate_activation_handler_url) | n} );
|
||||
}
|
||||
CertificatesPageFactory(
|
||||
${certificates | n, dump_js_escaped_json},
|
||||
"${certificate_url | n, js_escaped_string}",
|
||||
"${course_outline_url | n, js_escaped_string}",
|
||||
${course_modes | n, dump_js_escaped_json},
|
||||
${certificate_web_view_url | n, dump_js_escaped_json},
|
||||
${is_active | n, dump_js_escaped_json},
|
||||
${certificate_activation_handler_url | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
% endif
|
||||
</%block>
|
||||
|
||||
<%block name="content">
|
||||
|
||||
@@ -9,7 +9,9 @@ else:
|
||||
</%def>
|
||||
<%!
|
||||
from contentstore.views.helpers import xblock_studio_url, xblock_type_display_name
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
from util.markup import HTML, ugettext as _
|
||||
%>
|
||||
<%block name="title">${xblock.display_name_with_default_escaped} ${xblock_type_display_name(xblock) | h}</%block>
|
||||
@@ -32,11 +34,11 @@ from util.markup import HTML, ugettext as _
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/container"], function(ContainerFactory) {
|
||||
ContainerFactory(
|
||||
${ escape_json_dumps(component_templates) | n },
|
||||
${ escape_json_dumps(xblock_info) | n },
|
||||
"${action | h}",
|
||||
${component_templates | n, dump_js_escaped_json},
|
||||
${xblock_info | n, dump_js_escaped_json},
|
||||
"${action | n, js_escaped_string}",
|
||||
{
|
||||
isUnitPage: ${ escape_json_dumps(is_unit_page) | n },
|
||||
isUnitPage: ${is_unit_page | n, dump_js_escaped_json},
|
||||
canEdit: true
|
||||
}
|
||||
);
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.template.defaultfilters import escapejs
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
|
||||
## TODO decode course # from context_course into title.
|
||||
@@ -23,11 +24,11 @@ from openedx.core.lib.js_utils import escape_json_dumps
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/course_info"], function(CourseInfoFactory) {
|
||||
CourseInfoFactory(
|
||||
"${updates_url}",
|
||||
"${handouts_locator | escapejs}",
|
||||
"${base_asset_url}",
|
||||
${escape_json_dumps(push_notification_enabled) | n}
|
||||
);
|
||||
"${updates_url | n, js_escaped_string}",
|
||||
"${handouts_locator | n, js_escaped_string}",
|
||||
"${base_asset_url | n, js_escaped_string}",
|
||||
${push_notification_enabled | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import logging
|
||||
from util.date_utils import get_default_time_display
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import dump_js_escaped_json
|
||||
from contentstore.utils import reverse_usage_url
|
||||
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
|
||||
%>
|
||||
@@ -15,7 +15,10 @@ from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/outline"], function (OutlineFactory) {
|
||||
OutlineFactory(${escape_json_dumps(course_structure) | n}, ${escape_json_dumps(initial_state) | n});
|
||||
OutlineFactory(
|
||||
${course_structure | n, dump_js_escaped_json},
|
||||
${initial_state | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ else:
|
||||
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%block name="title">
|
||||
%if library:
|
||||
@@ -24,11 +26,11 @@ else:
|
||||
|
||||
<%block name="requirejs">
|
||||
% if in_err:
|
||||
var hasUnit = ${escape_json_dumps(bool(unit)) | n},
|
||||
editUnitUrl = "${edit_unit_url or ""}",
|
||||
courselikeHomeUrl = "${courselike_home_url or ""}",
|
||||
is_library = ${escape_json_dumps(library) | n}
|
||||
errMsg = ${escape_json_dumps(raw_err_msg or "") | n};
|
||||
var hasUnit = ${bool(unit) | n, dump_js_escaped_json},
|
||||
editUnitUrl = "${edit_unit_url | n, js_escaped_string}",
|
||||
courselikeHomeUrl = "${courselike_home_url | n, js_escaped_string}",
|
||||
is_library = ${library | n, dump_js_escaped_json}
|
||||
errMsg = "${raw_err_msg | n, js_escaped_string}";
|
||||
|
||||
require(["js/factories/export"], function(ExportFactory) {
|
||||
ExportFactory(hasUnit, editUnitUrl, courselikeHomeUrl, is_library, errMsg);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
<%!
|
||||
from contentstore import utils
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
|
||||
<%block name="title">${_("Group Configurations")}</%block>
|
||||
@@ -21,7 +23,13 @@ from openedx.core.lib.js_utils import escape_json_dumps
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/group_configurations"], function(GroupConfigurationsFactory) {
|
||||
GroupConfigurationsFactory(${escape_json_dumps(should_show_experiment_groups) | n}, ${escape_json_dumps(experiment_group_configurations) | n}, ${escape_json_dumps(content_group_configuration) | n}, "${group_configuration_url}", "${course_outline_url}");
|
||||
GroupConfigurationsFactory(
|
||||
${should_show_experiment_groups | n, dump_js_escaped_json},
|
||||
${experiment_group_configurations | n, dump_js_escaped_json},
|
||||
${content_group_configuration | n, dump_js_escaped_json},
|
||||
"${group_configuration_url | n, js_escaped_string}",
|
||||
"${course_outline_url | n, js_escaped_string}"
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ else:
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%block name="title">
|
||||
%if library:
|
||||
@@ -239,6 +241,9 @@ else:
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/import"], function(ImportFactory) {
|
||||
ImportFactory("${import_status_url}", ${escape_json_dumps(library) | n});
|
||||
ImportFactory(
|
||||
"${import_status_url | n, js_escaped_string}",
|
||||
${library | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<%!
|
||||
from contentstore.views.helpers import xblock_studio_url, xblock_type_display_name
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import dump_js_escaped_json
|
||||
%>
|
||||
<%block name="title">${context_library.display_name_with_default_escaped} ${xblock_type_display_name(context_library)}</%block>
|
||||
<%block name="bodyclass">is-signedin course container view-container view-library</%block>
|
||||
@@ -24,8 +24,8 @@ from openedx.core.lib.js_utils import escape_json_dumps
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/library"], function(LibraryFactory) {
|
||||
LibraryFactory(
|
||||
${escape_json_dumps(component_templates) | n},
|
||||
${escape_json_dumps(xblock_info) | n},
|
||||
${component_templates | n, dump_js_escaped_json},
|
||||
${xblock_info | n, dump_js_escaped_json},
|
||||
{
|
||||
isUnitPage: false,
|
||||
page_size: 10,
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%def name="online_help_token()"><% return "team_course" %></%def>
|
||||
<%block name="title">${_("Course Team Settings")}</%block>
|
||||
@@ -114,11 +117,11 @@ from openedx.core.lib.js_utils import escape_json_dumps
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/manage_users"], function(ManageCourseUsersFactory) {
|
||||
ManageCourseUsersFactory(
|
||||
"${context_course.display_name | h}",
|
||||
${escape_json_dumps(users) | n},
|
||||
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': unicode(context_course.id), 'email': '@@EMAIL@@'})}",
|
||||
${ request.user.id },
|
||||
${str(allow_actions).lower()}
|
||||
"${context_course.display_name_with_default | h}",
|
||||
${users | n, dump_js_escaped_json},
|
||||
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': unicode(context_course.id), 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
|
||||
${request.user.id | n, dump_js_escaped_json},
|
||||
${allow_actions | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%def name="online_help_token()"><% return "team_library" %></%def>
|
||||
<%block name="title">${_("Library User Access")}</%block>
|
||||
@@ -107,11 +110,11 @@ from openedx.core.lib.js_utils import escape_json_dumps
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/manage_users_lib"], function(ManageLibraryUsersFactory) {
|
||||
ManageLibraryUsersFactory(
|
||||
"${context_library.display_name_with_default_escaped | h}",
|
||||
${escape_json_dumps(users) | n},
|
||||
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': library_key, 'email': '@@EMAIL@@'})}",
|
||||
${ request.user.id },
|
||||
${str(allow_actions).lower()}
|
||||
"${context_library.display_name_with_default | h}",
|
||||
${users | n, dump_js_escaped_json},
|
||||
"${reverse('contentstore.views.course_team_handler', kwargs={'course_key_string': library_key, 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
|
||||
${request.user.id | n, dump_js_escaped_json},
|
||||
${allow_actions | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
import urllib
|
||||
from django.utils.translation import ugettext as _
|
||||
from contentstore import utils
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
|
||||
<%block name="header_extras">
|
||||
@@ -31,7 +33,10 @@ CMS.URL.UPLOAD_ASSET = '${upload_asset_url}';
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/settings"], function(SettingsFactory) {
|
||||
SettingsFactory("${details_url}", ${escape_json_dumps(show_min_grade_warning) | n});
|
||||
SettingsFactory(
|
||||
"${details_url | n, js_escaped_string}",
|
||||
${show_min_grade_warning | n, dump_js_escaped_json}
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from contentstore import utils
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%block name="title">${_("Advanced Settings")}</%block>
|
||||
<%block name="bodyclass">is-signedin course advanced view-settings</%block>
|
||||
@@ -19,7 +21,10 @@
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/settings_advanced"], function(SettingsAdvancedFactory) {
|
||||
SettingsAdvancedFactory(${escape_json_dumps(advanced_dict) | n}, "${advanced_settings_url}");
|
||||
SettingsAdvancedFactory(
|
||||
${advanced_dict | n, dump_js_escaped_json},
|
||||
"${advanced_settings_url | n, js_escaped_string}"
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
from contentstore import utils
|
||||
from django.utils.translation import ugettext as _
|
||||
from models.settings.encoder import CourseSettingsEncoder
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
|
||||
<%block name="header_extras">
|
||||
@@ -25,7 +27,11 @@
|
||||
</%block>
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/settings_graders"], function(SettingsGradersFactory) {
|
||||
SettingsGradersFactory(_.extend(${escape_json_dumps(course_details, cls=CourseSettingsEncoder) | n}, {is_credit_course: ${escape_json_dumps(is_credit_course) | n}}), "${grading_url}");
|
||||
SettingsGradersFactory(
|
||||
_.extend(${dump_js_escaped_json(course_details, cls=CourseSettingsEncoder) | n},
|
||||
{is_credit_course: ${is_credit_course | n, dump_js_escaped_json}}),
|
||||
"${grading_url | n, js_escaped_string}"
|
||||
);
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
from contentstore.views.helpers import xblock_studio_url
|
||||
from contentstore.utils import is_visible_to_specific_content_groups
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
)
|
||||
%>
|
||||
<%
|
||||
xblock_url = xblock_studio_url(xblock)
|
||||
@@ -24,10 +26,10 @@ messages = xblock.validate().to_json()
|
||||
<script>
|
||||
require(["jquery", "js/factories/xblock_validation"], function($, XBlockValidationFactory) {
|
||||
XBlockValidationFactory(
|
||||
${escape_json_dumps(messages) | n},
|
||||
$.parseJSON("${bool(xblock_url)}".toLowerCase()), // xblock_url will be None or a string
|
||||
$.parseJSON("${bool(is_root)}".toLowerCase()), // is_root will be None or a boolean
|
||||
$('div.xblock-validation-messages[data-locator="${xblock.location | h}"]')
|
||||
${messages | n, dump_js_escaped_json},
|
||||
${bool(xblock_url) | n, dump_js_escaped_json}, // xblock_url will be None or a string
|
||||
${bool(is_root) | n, dump_js_escaped_json}, // is_root will be None or a boolean
|
||||
$('div.xblock-validation-messages[data-locator="${xblock.location | n, js_escaped_string}"]')
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<%namespace name='static' file='static_content.html'/>
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from openedx.core.lib.js_utils import escape_json_dumps
|
||||
from openedx.core.djangolib.js_utils import dump_js_escaped_json
|
||||
%>
|
||||
|
||||
<%block name="title">${_("Textbooks")}</%block>
|
||||
@@ -28,7 +28,7 @@ CMS.URL.LMS_BASE = "${settings.LMS_BASE}"
|
||||
</%block>
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/textbooks"], function(TextbooksFactory) {
|
||||
TextbooksFactory(${escape_json_dumps(textbooks) | n});
|
||||
TextbooksFactory(${textbooks | n, dump_js_escaped_json});
|
||||
});
|
||||
</%block>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user