Exemplo n.º 1
0
def do_extends(parser, token):
    """
    Signal that this template extends a parent template.

    This tag may be used in two ways: ``{% extends "base" %}`` (with quotes)
    uses the literal value "base" as the name of the parent template to extend,
    or ``{% extends variable %}`` uses the value of ``variable`` as either the
    name of the parent template to extend (if it evaluates to a string) or as
    the parent template itself (if it evaluates to a Template object).
    """
    bits = token.split_contents()
    print('bits" ++++++++>', type(bits[1]))
    print('do_extends: ', token)
    if len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes one argument" % bits[0])
    site = Site.objects.get_current()
    bits[1] = '"{0}/{1}"'.format(site.domain, bits[1].strip("'").strip('"'))
    print('parser.origin.template_name: ', parser.origin.template_name)
    bits[1] = construct_relative_path(parser.origin.template_name, bits[1])
    parent_name = parser.compile_filter(bits[1])
    print('parent_name: ----------------------->', type(parent_name),
          parent_name)
    nodelist = parser.parse()
    if nodelist.get_nodes_by_type(ExtendsNode):
        raise TemplateSyntaxError(
            "'%s' cannot appear more than once in the same template" % bits[0])
    print(nodelist, parent_name)
    return ExtendsNode(nodelist, parent_name)
Exemplo n.º 2
0
def pjaxr_extends(parser, token):
    bits = token.split_contents()
    if len(bits) != 4 and len(bits) != 3 and len(bits) != 2:
        raise TemplateSyntaxError("'%s' takes 1 - 3 arguments" % bits[0])

    nodelist = parser.parse()

    if nodelist.get_nodes_by_type(
            PjaxrExtendsNode) or nodelist.get_nodes_by_type(ExtendsNode):
        raise TemplateSyntaxError(
            "'pjaxr_extends' and 'extends' cannot appear more than once in the same template!"
        )

    if len(bits) > 2:
        try:
            # format DEFAULT_PJAXR_TEMPLATE string to fit into FilterExpression as token
            pjaxr_template = parser.compile_filter(
                bits[3]) if (len(bits) == 4) else FilterExpression(
                    "'{0}'".format(settings.DEFAULT_PJAXR_TEMPLATE), parser)
        except AttributeError:
            raise TemplateSyntaxError(
                "No Pjaxr template set, even no default!")
        return PjaxrExtendsNode(nodelist, parser.compile_filter(bits[1]),
                                parser.compile_filter(bits[2]), pjaxr_template)
    return ExtendsNode(nodelist, parser.compile_filter(bits[1]))
Exemplo n.º 3
0
 def test_extends_node_repr(self):
     extends_node = ExtendsNode(
         nodelist=NodeList([]),
         parent_name=Node(),
         template_dirs=[],
     )
     self.assertEqual(repr(extends_node), "<ExtendsNode: extends None>")
Exemplo n.º 4
0
 def render(self, context):
     if self.templateVar:
         name = context[self.templateVar]
     else:
         name = self.templateName
     component = renderComponent(name)
     context['zcms_internal_component_'] = Template(component)
     return ExtendsNode.render(self, context)
Exemplo n.º 5
0
class IncludeExtendNode(template.Node):
  """
  The node that implements include_extend.

  Note that we can't inherit from ExtendsNode as only one ExtendsNode is
  allowed in a template, although the implementation is exactly the same.
  """
  def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
    self.impl = ExtendsNode(nodelist, parent_name, parent_name_expr,
                              template_dirs)
  def render(self, context):
    return self.impl.render(context)
Exemplo n.º 6
0
class IncludeExtendNode(template.Node):
  """
  The node that implements include_extend.

  Note that we can't inherit from ExtendsNode as only one ExtendsNode is
  allowed in a template, although the implementation is exactly the same.
  """
  def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
    self.impl = ExtendsNode(nodelist, parent_name, parent_name_expr,
                              template_dirs)
  def render(self, context):
    return self.impl.render(context)
Exemplo n.º 7
0
 def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
   self.impl = ExtendsNode(nodelist, parent_name, parent_name_expr,
                             template_dirs)
Exemplo n.º 8
0
 def render(self, context):
     parent_name = os.path.join(*[ var['type'] == 'var' and var['value'].resolve(context) or var['value'] for var in self.varlist ])
     ExtendsNode.__init__(self, nodelist = self.nodelist, parent_name = parent_name, parent_name_expr = None)
     return ExtendsNode.render(self, context)
Exemplo n.º 9
0
 def __init__(self, nodelist, template_name):
     self.delegate = ExtendsNode(nodelist, template_name, None)
Exemplo n.º 10
0
class CallNode(Node):
    def __init__(self, nodelist, template_name):
        self.delegate = ExtendsNode(nodelist, template_name, None)

    def render(self, context):
        return self.delegate.render(context)
Exemplo n.º 11
0
 def __init__(self, nodelist, contextNameExpr, templateName = None, templateVar = None):
     ExtendsNode.__init__(self, nodelist, None, contextNameExpr)
     self.templateName = templateName
     self.templateVar = templateVar
Exemplo n.º 12
0
 def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
   self.impl = ExtendsNode(nodelist, parent_name, parent_name_expr,
                             template_dirs)