From d5306eccf4ec17b523ae6832608a00edf3755b43 Mon Sep 17 00:00:00 2001 From: Gary Smith Date: Wed, 5 Apr 2017 15:19:55 -0700 Subject: [PATCH] Restore the ability to load external templates Change the Theme Template loader to not absolutely require that templates reside under the Django directory (openstack_dashboard), by deferring the usage of safe_join to the point where that check is made and handled correctly. Also addressed on Pythonic nit noted in the review of https://review.openstack.org/317051 Closes-Bug: #1680265 Change-Id: Icf86df5e213d47b207e99b721e9e0fcdc898882e --- horizon/themes.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/horizon/themes.py b/horizon/themes.py index 9f2471f2ed..be5b37086d 100644 --- a/horizon/themes.py +++ b/horizon/themes.py @@ -133,7 +133,9 @@ class ThemeTemplateLoader(tLoaderCls): pass try: - template_path = safe_join( + # To support themes residing outside of Django, use os.path.join to + # avoid throwing a SuspiciousFileOperation and immediately exiting. + template_path = os.path.join( getattr( settings, 'ROOT_PATH', @@ -149,12 +151,9 @@ class ThemeTemplateLoader(tLoaderCls): yield os.path.join( this_theme[2], 'templates', template_name ) - elif template_name.find(template_path) != -1: + elif template_path in template_name: yield template_name - except SuspiciousFileOperation: - # In case we are loading a theme outside of Django, pass along - pass except UnicodeDecodeError: # The template dir name wasn't valid UTF-8. raise