示例#1
0
 def parse(self, template_name):
     try:
         return get_template(template_name).template
     except template.TemplateSyntaxError as e:
         raise TemplateSyntaxError(str(e))
     except template.TemplateDoesNotExist as e:
         raise TemplateDoesNotExist(str(e))
示例#2
0
 def parse(self, template_name):
     with io.open(template_name, mode='rb') as file:
         try:
             return Template(file.read().decode(self.charset))
         except template.TemplateSyntaxError as e:
             raise TemplateSyntaxError(str(e))
         except template.TemplateDoesNotExist as e:
             raise TemplateDoesNotExist(str(e))
 def parse(self, template_name):
     try:
         if django.VERSION < (1, 8):
             return get_template(template_name)
         else:
             return get_template(template_name).template
     except template.TemplateSyntaxError as e:
         raise TemplateSyntaxError(str(e))
     except template.TemplateDoesNotExist as e:
         raise TemplateDoesNotExist(str(e))
示例#4
0
    def parse(self, template_name):
        with io.open(template_name, mode='rb') as file:
            try:
                template = self.env.parse(file.read().decode(self.charset))
            except jinja2.TemplateSyntaxError as e:
                raise TemplateSyntaxError(str(e))
            except jinja2.TemplateNotFound as e:
                raise TemplateDoesNotExist(str(e))

        return template
示例#5
0
    def get_nodelist(self, node):
        if isinstance(node, ExtendsNode):
            try:
                return handle_extendsnode(node)
            except template.TemplateSyntaxError as e:
                raise TemplateSyntaxError(str(e))
            except template.TemplateDoesNotExist as e:
                raise TemplateDoesNotExist(str(e))

        # Check if node is an ```if``` switch with true and false branches
        nodelist = []
        if isinstance(node, Node):
            for attr in node.child_nodelists:
                nodelist += getattr(node, attr, [])
        else:
            nodelist = getattr(node, 'nodelist', [])
        return nodelist
示例#6
0
    def get_nodelist(self, node, original, context=None):
        if isinstance(node, ExtendsNode):
            try:
                if context is None:
                    context = Context()
                context.template = original
                return handle_extendsnode(node, context)
            except template.TemplateSyntaxError as e:
                raise TemplateSyntaxError(str(e))
            except template.TemplateDoesNotExist as e:
                raise TemplateDoesNotExist(str(e))

        # Check if node is an ```if``` switch with true and false branches
        nodelist = []
        if isinstance(node, Node):
            for attr in node.child_nodelists:
                nodelist += getattr(node, attr, [])
        else:
            nodelist = getattr(node, "nodelist", [])
        return nodelist
示例#7
0
    def get_nodelist(self, node, original, context=None):
        if isinstance(node, ExtendsNode):
            try:
                if context is None:
                    context = Context()
                context.template = original
                return handle_extendsnode(node, context)
            except template.TemplateSyntaxError as e:
                raise TemplateSyntaxError(str(e))
            except template.TemplateDoesNotExist as e:
                raise TemplateDoesNotExist(str(e))

        # Check if node is an ```if``` switch with true and false branches
        nodelist = []
        if isinstance(node, Node):
            for attr in node.child_nodelists:
                # see https://github.com/django-compressor/django-compressor/pull/825
                # and linked issues/PRs for a discussion on the `None) or []` part
                nodelist += getattr(node, attr, None) or []
        else:
            nodelist = getattr(node, 'nodelist', [])
        return nodelist
示例#8
0
    def get_nodelist(self, node, original):
        if isinstance(node, ExtendsNode):
            try:
                context = Context()
                context.template = original
                # TODO: We are passing an empty context when finding base
                # templates. This does not work when extending using
                # variables ({% extends template_var %}).
                # A refactor might be needed to support that use-case with
                # multiple offline contexts.
                return handle_extendsnode(node, context)
            except template.TemplateSyntaxError as e:
                raise TemplateSyntaxError(str(e))
            except template.TemplateDoesNotExist as e:
                raise TemplateDoesNotExist(str(e))

        # Check if node is an ```if``` switch with true and false branches
        nodelist = []
        if isinstance(node, Node):
            for attr in node.child_nodelists:
                nodelist += getattr(node, attr, [])
        else:
            nodelist = getattr(node, 'nodelist', [])
        return nodelist