Merge pull request #17009 from cpennington/cms-login-factory-page
Convert cms login.html to the require_page pattern in preparation for…
This commit is contained in:
@@ -148,3 +148,4 @@ SECRET_KEY = uuid.uuid4().hex
|
||||
############################### PIPELINE #######################################
|
||||
|
||||
PIPELINE_ENABLED = False
|
||||
REQUIRE_DEBUG = True
|
||||
|
||||
@@ -1128,6 +1128,9 @@ INSTALLED_APPS = [
|
||||
|
||||
# Entitlements, used in openedx tests
|
||||
'entitlements',
|
||||
|
||||
# Asset management for mako templates
|
||||
'pipeline_mako',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
'js/certificates/factories/certificates_page_factory',
|
||||
'js/factories/index',
|
||||
'js/factories/library',
|
||||
'js/factories/login',
|
||||
'js/pages/login',
|
||||
'js/factories/manage_users',
|
||||
'js/factories/outline',
|
||||
'js/factories/register',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(['jquery.cookie', 'utility', 'common/js/components/utils/view_utils'], function(cookie, utility, ViewUtils) {
|
||||
'use strict';
|
||||
return function(homepageURL) {
|
||||
return function LoginFactory(homepageURL) {
|
||||
function postJSON(url, data, callback) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
|
||||
11
cms/static/js/pages/login.js
Normal file
11
cms/static/js/pages/login.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function(define) {
|
||||
'use strict';
|
||||
|
||||
define(
|
||||
['js/factories/login', 'common/js/utils/page_factory'],
|
||||
function(LoginFactory, invokePageFactory) {
|
||||
invokePageFactory('LoginFactory', LoginFactory);
|
||||
}
|
||||
);
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
@@ -143,6 +143,7 @@ from openedx.core.djangolib.markup import HTML
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<%block name='requirejs_page'></%block>
|
||||
<%include file="widgets/segment-io-footer.html" />
|
||||
<div class="modal-cover"></div>
|
||||
</body>
|
||||
|
||||
@@ -54,8 +54,8 @@ from openedx.core.djangolib.js_utils import js_escaped_string
|
||||
</div>
|
||||
</%block>
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/login"], function(LoginFactory) {
|
||||
LoginFactory("${reverse('homepage') | n, js_escaped_string}");
|
||||
});
|
||||
<%block name="requirejs_page">
|
||||
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
|
||||
"${reverse('homepage') | n, js_escaped_string}"
|
||||
</%static:require_page>
|
||||
</%block>
|
||||
|
||||
@@ -111,7 +111,7 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
${HTML(render_bundle(page))}
|
||||
</%def>
|
||||
|
||||
<%def name="webpack(entry)">
|
||||
<%def name="webpack(entry, extension=None, config='DEFAULT', attrs='')">
|
||||
<%doc>
|
||||
Loads Javascript onto your page from a Webpack-generated bundle.
|
||||
Uses the Django template engine because our webpack loader only provides template tags for Jinja and Django.
|
||||
@@ -119,7 +119,7 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
<%
|
||||
body = capture(caller.body)
|
||||
%>
|
||||
${HTML(render_bundle(entry))}
|
||||
${HTML(render_bundle(entry, extension=None, config='DEFAULT', attrs=attrs))}
|
||||
% if body:
|
||||
<script type="text/javascript">
|
||||
${body | n, decode.utf8}
|
||||
@@ -154,6 +154,36 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="require_page(page_name, class_name)">
|
||||
<%doc>
|
||||
Loads Javascript onto your page synchronously.
|
||||
Uses RequireJS in development and a plain script tag in production.
|
||||
The body of the tag should be a comma-separated list of arguments
|
||||
to be passed to the page factory specified by the class_name argument.
|
||||
</%doc>
|
||||
<%
|
||||
body = capture(caller.body)
|
||||
%>
|
||||
<script type="text/javascript">
|
||||
if (typeof pageFactoryArguments == "undefined") {
|
||||
var pageFactoryArguments = {};
|
||||
}
|
||||
% if body:
|
||||
pageFactoryArguments['${class_name | n, js_escaped_string}'] = [${ body | n, decode.utf8 }];
|
||||
% else:
|
||||
pageFactoryArguments['${class_name | n, js_escaped_string}'] = [];
|
||||
% endif
|
||||
</script>
|
||||
% if not settings.REQUIRE_DEBUG:
|
||||
<script type="text/javascript" src="${staticfiles_storage.url(page_name + '.js') + '?raw'}"></script>
|
||||
% endif
|
||||
<script type="text/javascript">
|
||||
(function (require) {
|
||||
require(['${page_name | n, js_escaped_string}']);
|
||||
}).call(this, require || RequireJS.require);
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="require_module(module_name, class_name)">
|
||||
<%doc>
|
||||
Loads Javascript onto your page synchronously.
|
||||
|
||||
27
common/static/common/js/utils/page_factory.js
Normal file
27
common/static/common/js/utils/page_factory.js
Normal file
@@ -0,0 +1,27 @@
|
||||
define([], function() {
|
||||
'use strict';
|
||||
|
||||
return function invokePageFactory(name, factory) {
|
||||
var args;
|
||||
|
||||
if (typeof window.pageFactoryArguments === 'undefined') {
|
||||
throw Error(
|
||||
'window.pageFactoryArguments must be initialized before calling invokePageFactory(' +
|
||||
name +
|
||||
'). Use the <%static:require_page> template tag.'
|
||||
);
|
||||
}
|
||||
args = window.pageFactoryArguments[name];
|
||||
|
||||
if (typeof args === 'undefined') {
|
||||
throw Error(
|
||||
'window.pageFactoryArguments["' +
|
||||
name +
|
||||
'"] must be initialized before calling invokePageFactory(' +
|
||||
name +
|
||||
'). Use the <%static:require_page> template tag.'
|
||||
);
|
||||
}
|
||||
factory.apply(null, window.pageFactoryArguments[name]);
|
||||
};
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
<%namespace name='static' file='/static_content.html'/>
|
||||
<%page expression_filter="h"/>
|
||||
|
||||
<%inherit file="base.html" />
|
||||
@@ -51,8 +52,8 @@ from openedx.core.djangolib.js_utils import js_escaped_string
|
||||
</div>
|
||||
</%block>
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/login"], function(LoginFactory) {
|
||||
LoginFactory("${reverse('homepage') | n, js_escaped_string }");
|
||||
});
|
||||
<%block name="requirejs_page">
|
||||
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
|
||||
"${reverse('homepage') | n, js_escaped_string}"
|
||||
</%static:require_page>
|
||||
</%block>
|
||||
|
||||
@@ -14,5 +14,5 @@ from cms.conftest import _django_clear_site_cache, pytest_configure # pylint: d
|
||||
def no_webpack_loader(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"webpack_loader.templatetags.webpack_loader.render_bundle",
|
||||
lambda x: ''
|
||||
lambda entry, extension=None, config='DEFAULT', attrs='': ''
|
||||
)
|
||||
|
||||
@@ -314,7 +314,7 @@ class RuleViolation(object):
|
||||
found.
|
||||
|
||||
"""
|
||||
pragma_match = re.search(r'xss-lint:\s*disable=([a-zA-Z,-]+)', string)
|
||||
pragma_match = re.search(r'xss-lint:\s*disable=([a-zA-Z,\- ]+)', string)
|
||||
if pragma_match is None:
|
||||
return
|
||||
if scope_start_string:
|
||||
@@ -324,7 +324,7 @@ class RuleViolation(object):
|
||||
return
|
||||
|
||||
for disabled_rule in pragma_match.group(1).split(','):
|
||||
if disabled_rule == self.rule.rule_id:
|
||||
if disabled_rule.strip() == self.rule.rule_id:
|
||||
self.is_disabled = True
|
||||
return
|
||||
|
||||
@@ -2383,6 +2383,8 @@ class MakoTemplateLinter(BaseLinter):
|
||||
</script> | # script tag end
|
||||
<%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version)
|
||||
</%static:require_module(_async)?> | # require js script tag end (optionally the _async version)
|
||||
<%static:require_page.*?> | # require js script tag start
|
||||
</%static:require_page> | # require js script tag end
|
||||
<%static:webpack.*?> | # webpack script tag start
|
||||
</%static:webpack> | # webpack script tag end
|
||||
<%static:studiofrontend.*?> | # studiofrontend script tag start
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<%namespace name='static' file='/static_content.html'/>
|
||||
<%page expression_filter="h"/>
|
||||
|
||||
<%inherit file="base.html" />
|
||||
@@ -50,8 +51,8 @@ from django.utils.translation import ugettext as _
|
||||
</div>
|
||||
</%block>
|
||||
|
||||
<%block name="requirejs">
|
||||
require(["js/factories/login"], function(LoginFactory) {
|
||||
LoginFactory("${reverse('homepage')}");
|
||||
});
|
||||
<%block name="requirejs_page">
|
||||
<%static:require_page page_name="js/pages/login" class_name="LoginFactory">
|
||||
"${reverse('homepage') | n, js_escaped_string}"
|
||||
</%static:require_page>
|
||||
</%block>
|
||||
|
||||
Reference in New Issue
Block a user