def _get_loaders(self): """Tries to translate each template loader given in the Django settings (:mod:`django.settings`) to a similarly-behaving Jinja loader. Warns if a similar loader cannot be found. Allows for Jinja2 loader instances to be placed in the template loader settings. """ loaders = [] from coffin.template.loaders import jinja_loader_from_django_loader from jinja2.loaders import BaseLoader as JinjaLoader from django.conf import settings _loaders = getattr(settings, "JINJA2_TEMPLATE_LOADERS", settings.TEMPLATE_LOADERS) for loader in _loaders: if isinstance(loader, JinjaLoader): loaders.append(loader) else: loader_name = args = None if isinstance(loader, basestring): loader_name = loader args = [] elif isinstance(loader, (tuple, list)): loader_name = loader[0] args = loader[1] if loader_name: loader_obj = jinja_loader_from_django_loader(loader_name, args) if loader_obj: loaders.append(loader_obj) continue warnings.warn("Cannot translate loader: %s" % loader) return loaders
def _get_loaders(self): """Tries to translate each template loader given in the Django settings (:mod:`django.settings`) to a similarly-behaving Jinja loader. Warns if a similar loader cannot be found. Allows for Jinja2 loader instances to be placed in the template loader settings. """ loaders = [] from coffin.template.loaders import jinja_loader_from_django_loader from jinja2.loaders import BaseLoader as JinjaLoader from django.conf import settings _loaders = getattr(settings, 'JINJA2_TEMPLATE_LOADERS', settings.TEMPLATE_LOADERS) for loader in _loaders: if isinstance(loader, JinjaLoader): loaders.append(loader) else: loader_name = args = None if isinstance(loader, basestring): loader_name = loader args = [] elif isinstance(loader, (tuple, list)): loader_name = loader[0] args = loader[1] if loader_name: loader_obj = jinja_loader_from_django_loader(loader_name, args) if loader_obj: loaders.append(loader_obj) continue warnings.warn('Cannot translate loader: %s' % loader) return loaders
def get_loaders(): loaders = [] from django.conf import settings for loader in settings.TEMPLATE_LOADERS: if isinstance(loader, basestring): loader_obj = jinja_loader_from_django_loader(loader) if loader_obj: loaders.append(loader_obj) else: warnings.warn('Cannot translate loader: %s' % loader) else: # It's assumed to be a Jinja2 loader instance. loaders.append(loader) return loaders
def get_django_template(name, dirs=None): global django_template_source_loaders if django_template_source_loaders is None: loaders = [] for loader_name in settings.JINJA2_TEMPLATE_LOADERS: loader = find_template_loader(loader_name) if loader is not None: loaders.append(loader) django_template_source_loaders = tuple(loaders) for loader in django_template_source_loaders: try: source, display_name = loader(name, dirs) return (source, make_origin(display_name, loader, name, dirs)) except TemplateDoesNotExist: pass raise TemplateDoesNotExist(name)
def _get_loaders(self): """Tries to translate each template loader given in the Django settings (:mod:`django.settings`) to a similarly-behaving Jinja loader. Warns if a similar loader cannot be found. Allows for Jinja2 loader instances to be placed in the template loader settings. """ loaders = [] from coffin.template.loaders import jinja_loader_from_django_loader from django.conf import settings for loader in settings.TEMPLATE_LOADERS: if isinstance(loader, basestring): loader_obj = jinja_loader_from_django_loader(loader) if loader_obj: loaders.append(loader_obj) else: warnings.warn('Cannot translate loader: %s' % loader) else: # It's assumed to be a Jinja2 loader instance. loaders.append(loader) return loaders