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(): ...@@ -63,3 +63,14 @@ def microsite_css_overrides_file():
return "<link href='{}' rel='stylesheet' type='text/css'>".format(static(file_path)) return "<link href='{}' rel='stylesheet' type='text/css'>".format(static(file_path))
else: else:
return "" 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): ...@@ -32,3 +32,10 @@ class MicroSiteTests(TestCase):
expected = u'my | less specific | Page | edX' expected = u'my | less specific | Page | edX'
title = microsite.page_title_breadcrumbs_tag(None, *crumbs) title = microsite.page_title_breadcrumbs_tag(None, *crumbs)
self.assertEqual(expected, title) 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(): ...@@ -31,6 +31,9 @@ def run():
if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False): if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
enable_third_party_auth() enable_third_party_auth()
if settings.FEATURES.get('USE_MICROSITES', False):
enable_microsites_pre_startup()
django.setup() django.setup()
autostartup() autostartup()
...@@ -116,6 +119,18 @@ def enable_stanford_theme(): ...@@ -116,6 +119,18 @@ def enable_stanford_theme():
settings.LOCALE_PATHS = (theme_root / 'conf/locale',) + settings.LOCALE_PATHS 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(): def enable_microsites():
""" """
Enable the use of microsites, which are websites that allow Enable the use of microsites, which are websites that allow
...@@ -151,7 +166,6 @@ def enable_microsites(): ...@@ -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 we have any valid microsites defined, let's wire in the Mako and STATIC_FILES search paths
if microsite_config_dict: if microsite_config_dict:
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].append(microsites_root)
edxmako.paths.add_lookup('main', microsites_root) edxmako.paths.add_lookup('main', microsites_root)
settings.STATICFILES_DIRS.insert(0, microsites_root) settings.STATICFILES_DIRS.insert(0, microsites_root)
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
{% block headextra %}{% endblock %} {% block headextra %}{% endblock %}
{% render_block "css" %} {% render_block "css" %}
{% optional_include "head-extra.html" %} {% optional_include "head-extra.html"|microsite_template_path %}
<meta name="path_prefix" content="{{EDX_ROOT_URL}}"> <meta name="path_prefix" content="{{EDX_ROOT_URL}}">
</head> </head>
...@@ -28,14 +28,14 @@ ...@@ -28,14 +28,14 @@
<div class="window-wrap" dir="${static.dir_rtl()}"> <div class="window-wrap" dir="${static.dir_rtl()}">
<a class="nav-skip" href="{% block nav_skip %}#content{% endblock %}">{% trans "Skip to main content" %}</a> <a class="nav-skip" href="{% block nav_skip %}#content{% endblock %}">{% trans "Skip to main content" %}</a>
{% with course=request.course %} {% with course=request.course %}
{% include "header.html" %} {% include "header.html"|microsite_template_path %}
{% endwith %} {% endwith %}
<div class="content-wrapper" id="content"> <div class="content-wrapper" id="content">
{% block body %}{% endblock %} {% block body %}{% endblock %}
{% block bodyextra %}{% endblock %} {% block bodyextra %}{% endblock %}
</div> </div>
{% with course=request.course %} {% with course=request.course %}
{% include "footer.html" %} {% include "footer.html"|microsite_template_path %}
{% endwith %} {% endwith %}
</div> </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