diff --git a/common/djangoapps/microsite_configuration/templatetags/microsite.py b/common/djangoapps/microsite_configuration/templatetags/microsite.py index fe54cce68f..a8e2095636 100644 --- a/common/djangoapps/microsite_configuration/templatetags/microsite.py +++ b/common/djangoapps/microsite_configuration/templatetags/microsite.py @@ -63,3 +63,14 @@ def microsite_css_overrides_file(): return "".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 diff --git a/common/djangoapps/microsite_configuration/tests/test_microsites.py b/common/djangoapps/microsite_configuration/tests/test_microsites.py index 01cf04aa8a..74b4f849d4 100644 --- a/common/djangoapps/microsite_configuration/tests/test_microsites.py +++ b/common/djangoapps/microsite_configuration/tests/test_microsites.py @@ -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) diff --git a/lms/startup.py b/lms/startup.py index 465b5e71c6..bc14bb2e86 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -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) diff --git a/lms/templates/main_django.html b/lms/templates/main_django.html index a7245f0cef..f8e4fc62ff 100644 --- a/lms/templates/main_django.html +++ b/lms/templates/main_django.html @@ -19,7 +19,7 @@ {% block headextra %}{% endblock %} {% render_block "css" %} - {% optional_include "head-extra.html" %} + {% optional_include "head-extra.html"|microsite_template_path %} @@ -28,14 +28,14 @@
{% trans "Skip to main content" %} {% with course=request.course %} - {% include "header.html" %} + {% include "header.html"|microsite_template_path %} {% endwith %}
{% block body %}{% endblock %} {% block bodyextra %}{% endblock %}
{% with course=request.course %} - {% include "footer.html" %} + {% include "footer.html"|microsite_template_path %} {% endwith %}