Template loaders defined before local settings

TEMPLATE_LOADERS was defined after loading local_settings.py and was sqashing
any attempt to customize the template loaders.
This patch adds CACHED_TEMPLATE_LOADERS, ADD_TEMPLATE_LOADERS and a doc
defining how to use them in order to ease customization process.

Change-Id: I2544529ee965ef01c6ac4973056801ebee50be6d
Closes-Bug: #1568764
This commit is contained in:
Yves-Gwenael Bourhis 2016-04-11 13:40:44 +02:00
parent 018df171fb
commit 17176d0617
3 changed files with 50 additions and 7 deletions

View File

@ -1582,10 +1582,42 @@ Default: ``True``
Controls whether unhandled exceptions should generate a generic 500 response
or present the user with a pretty-formatted debug information page.
When set, CACHED_TEMPLATE_LOADERS will not be cached.
This setting should **always** be set to ``False`` for production deployments
as the debug page can display sensitive information to users and attackers
alike.
``TEMPLATE_LOADERS``
---------------------------
.. versionadded:: 10.0.0(Newton)
These template loaders will be the first loaders and get loaded before the
CACHED_TEMPLATE_LOADERS. Use ADD_TEMPLATE_LOADERS if you want to add loaders at
the end and not cache loaded templates.
After the whole settings process has gone through, TEMPLATE_LOADERS will be:
TEMPLATE_LOADERS += (
('django.template.loaders.cached.Loader', CACHED_TEMPLATE_LOADERS),
) + tuple(ADD_TEMPLATE_LOADERS)
``CACHED_TEMPLATE_LOADERS``
---------------------------
.. versionadded:: 10.0.0(Newton)
Template loaders defined here will have their output cached if DEBUG
is set to False.
``ADD_TEMPLATE_LOADERS``
---------------------------
.. versionadded:: 10.0.0(Newton)
Template loaders defined here will be be loaded at the end of TEMPLATE_LOADERS,
after the CACHED_TEMPLATE_LOADERS and will never have a cached output.
``SECRET_KEY``
--------------

View File

@ -123,6 +123,15 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'openstack_dashboard.context_processors.openstack',
)
TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader',)
CACHED_TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'horizon.loaders.TemplateLoader',)
ADD_TEMPLATE_LOADERS = []
TEMPLATE_DIRS = (
os.path.join(ROOT_PATH, 'templates'),
)
@ -283,15 +292,12 @@ try:
except ImportError:
logging.warning("No local_settings file found.")
_LOADERS = ('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'horizon.loaders.TemplateLoader',)
if DEBUG:
TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader',) + _LOADERS
TEMPLATE_LOADERS += CACHED_TEMPLATE_LOADERS + tuple(ADD_TEMPLATE_LOADERS)
else:
TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader',
('django.template.loaders.cached.Loader', _LOADERS),)
TEMPLATE_LOADERS += (
('django.template.loaders.cached.Loader', CACHED_TEMPLATE_LOADERS),
) + tuple(ADD_TEMPLATE_LOADERS)
# allow to drop settings snippets into a local_settings_dir
LOCAL_SETTINGS_DIR_PATH = os.path.join(ROOT_PATH, "local", "local_settings.d")

View File

@ -0,0 +1,5 @@
---
upgrade:
- The final django TEMPLATE_LOADERS configuration will now be generated from
TEMPLATE_LOADERS, CACHED_TEMPLATE_LOADERS and ADD_TEMPLATE_LOADERS
settings. See the settings documentation for more information.