コード例 #1
0
ファイル: common.py プロジェクト: havard024/prego
    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
コード例 #2
0
    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
コード例 #3
0
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
コード例 #4
0
ファイル: loaders.py プロジェクト: desres/coffin
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)
コード例 #5
0
ファイル: loaders.py プロジェクト: MyBook/coffin
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)
コード例 #6
0
ファイル: common.py プロジェクト: brianmcdonnell/coffin
    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
コード例 #7
0
ファイル: common.py プロジェクト: FRiMN/coffin
    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