From efa8bd6755a2a84fea1dfa54a8531554d27e50f8 Mon Sep 17 00:00:00 2001 From: Bertrand Marron Date: Thu, 6 Mar 2014 17:04:51 +0100 Subject: [PATCH] Add method to clear mako template lookups Quick and dirty fix (edxapp.startup.run is called twice, once before loading the configuration, so the paths defined in lms.startup are basically ignored). --- common/djangoapps/edxmako/__init__.py | 2 +- common/djangoapps/edxmako/paths.py | 7 +++++++ common/djangoapps/edxmako/startup.py | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/edxmako/__init__.py b/common/djangoapps/edxmako/__init__.py index 613342b35a..981d640bc0 100644 --- a/common/djangoapps/edxmako/__init__.py +++ b/common/djangoapps/edxmako/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. LOOKUP = {} -from .paths import add_lookup, lookup_template +from .paths import add_lookup, lookup_template, clear_lookups diff --git a/common/djangoapps/edxmako/paths.py b/common/djangoapps/edxmako/paths.py index 8601110ddd..a29a68e8b3 100644 --- a/common/djangoapps/edxmako/paths.py +++ b/common/djangoapps/edxmako/paths.py @@ -22,6 +22,13 @@ class DynamicTemplateLookup(TemplateLookup): self.directories.append(os.path.normpath(directory)) +def clear_lookups(namespace): + """ + Remove mako template lookups for the given namespace. + """ + if namespace in LOOKUP: + del LOOKUP[namespace] + def add_lookup(namespace, directory, package=None): """ Adds a new mako template lookup directory to the given namespace. diff --git a/common/djangoapps/edxmako/startup.py b/common/djangoapps/edxmako/startup.py index 2ecc8b231e..7d291b4bc0 100644 --- a/common/djangoapps/edxmako/startup.py +++ b/common/djangoapps/edxmako/startup.py @@ -2,7 +2,7 @@ Initialize the mako template lookup """ from django.conf import settings -from . import add_lookup +from . import add_lookup, clear_lookups def run(): @@ -14,5 +14,6 @@ def run(): """ template_locations = settings.MAKO_TEMPLATES for namespace, directories in template_locations.items(): + clear_lookups(namespace) for directory in directories: add_lookup(namespace, directory)