This commit is contained in:
Kevin Mooney 2015-04-16 17:23:45 +00:00
commit 2ffeb0a133
3 changed files with 29 additions and 13 deletions

View file

@ -14,6 +14,12 @@ class DbTemplatesConf(AppConf):
AUTO_POPULATE_CONTENT = True
MEDIA_PREFIX = None
CACHE_BACKEND = None
TEMPLATE_LOADERS = None
def configure_template_loaders(self, value):
if value is None:
value = getattr(settings, "TEMPLATE_LOADERS", [])
return value
def configure_media_prefix(self, value):
if value is None:

View file

@ -1,29 +1,32 @@
from django import VERSION
from django.template import (Template, TemplateDoesNotExist,
TemplateSyntaxError)
from django.template.loader import find_template_loader
from django.utils.importlib import import_module
from dbtemplates.conf import settings
DBTEMPLATES_TEMPLATE_LOADERS = settings.DBTEMPLATES_TEMPLATE_LOADERS
loader_cache = None
def get_loaders():
from django.template.loader import template_source_loaders
if template_source_loaders is None:
try:
from django.template.loader import find_template as finder
except ImportError:
from django.template.loader import find_template_source as finder # noqa
try:
source, name = finder('test')
except TemplateDoesNotExist:
pass
from django.template.loader import template_source_loaders
return template_source_loaders or []
global loader_cache
if loader_cache is not None:
return loader_cache
loader_cache = []
for loader_name in DBTEMPLATES_TEMPLATE_LOADERS:
loader = find_template_loader(loader_name)
if loader is not None:
loader_cache.append(loader)
return loader_cache
def get_template_source(name):
source = None
for loader in get_loaders():
if loader.__module__.startswith('dbtemplates.'):
# Don't give a damn about dbtemplates' own loader.
# Don't give a damn about dbtemplates' own loader or loaders
# that use the dbtemplates loader
continue
module = import_module(loader.__module__)
load_template_source = getattr(module, 'load_template_source', None)

View file

@ -22,6 +22,13 @@ To disable this feature set ``DBTEMPLATES_AUTO_POPULATE_CONTENT`` to
The dotted Python path to the cache backend class. See
:ref:`Caching <caching>` for details.
``DBTEMPLATES_TEMPLATE_LOADERS``
--------------------------------
A tuple of Template loaders that dbtemplates should use when trying to
autopopulate dbtemplates from the database. Set to the value of
``settings.TEMPLATE_LOADERS`` by default.
``DBTEMPLATES_USE_CODEMIRROR``
------------------------------