Commit f2a6a27e by Felipe Montoya

Adding support for microsite template_paths on django templates

Stripping the leading / for the django_templates finder

Enabling the microsite configurations before running django.setup()

Adding only the templates directory before startup

Adding the missing overrides file at the django templates main

Using the comp_theming way of overriding css

Adding test for the microsite_template_path filter
parent 41195761
......@@ -63,3 +63,14 @@ def microsite_css_overrides_file():
return "<link href='{}' rel='stylesheet' type='text/css'>".format(static(file_path))
else:
return ""
@register.filter
def microsite_template_path(template_name):
"""
Django template filter to apply template overriding to microsites.
The django_templates loader does not support the leading slash, therefore
it is stripped before returning.
"""
template_name = microsite.get_template_path(template_name)
return template_name[1:] if template_name[0] == '/' else template_name
......@@ -32,3 +32,10 @@ class MicroSiteTests(TestCase):
expected = u'my | less specific | Page | edX'
title = microsite.page_title_breadcrumbs_tag(None, *crumbs)
self.assertEqual(expected, title)
def test_microsite_template_path(self):
"""
When an unexistent path is passed to the filter, it should return the same path
"""
path = microsite.microsite_template_path('footer.html')
self.assertEqual("footer.html", path)
......@@ -31,6 +31,9 @@ def run():
if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
enable_third_party_auth()
if settings.FEATURES.get('USE_MICROSITES', False):
enable_microsites_pre_startup()
django.setup()
autostartup()
......@@ -116,6 +119,18 @@ def enable_stanford_theme():
settings.LOCALE_PATHS = (theme_root / 'conf/locale',) + settings.LOCALE_PATHS
def enable_microsites_pre_startup():
"""
The TEMPLATE_ENGINE directory to search for microsite templates
in non-mako templates must be loaded before the django startup
"""
microsites_root = settings.MICROSITE_ROOT_DIR
microsite_config_dict = settings.MICROSITE_CONFIGURATION
if microsite_config_dict:
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].append(microsites_root)
def enable_microsites():
"""
Enable the use of microsites, which are websites that allow
......@@ -151,7 +166,6 @@ def enable_microsites():
# if we have any valid microsites defined, let's wire in the Mako and STATIC_FILES search paths
if microsite_config_dict:
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].append(microsites_root)
edxmako.paths.add_lookup('main', microsites_root)
settings.STATICFILES_DIRS.insert(0, microsites_root)
......
......@@ -19,7 +19,7 @@
{% block headextra %}{% endblock %}
{% render_block "css" %}
{% optional_include "head-extra.html" %}
{% optional_include "head-extra.html"|microsite_template_path %}
<meta name="path_prefix" content="{{EDX_ROOT_URL}}">
</head>
......@@ -28,14 +28,14 @@
<div class="window-wrap" dir="${static.dir_rtl()}">
<a class="nav-skip" href="{% block nav_skip %}#content{% endblock %}">{% trans "Skip to main content" %}</a>
{% with course=request.course %}
{% include "header.html" %}
{% include "header.html"|microsite_template_path %}
{% endwith %}
<div class="content-wrapper" id="content">
{% block body %}{% endblock %}
{% block bodyextra %}{% endblock %}
</div>
{% with course=request.course %}
{% include "footer.html" %}
{% include "footer.html"|microsite_template_path %}
{% endwith %}
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment