Ticket #5124: must_be_first.diff

File must_be_first.diff, 1.6 KB (added by k0001, 17 years ago)

adds support for a new Node property "must_be_first"

  • django/template/__init__.py

     
    311311        return NodeList()
    312312
    313313    def extend_nodelist(self, nodelist, node, token):
     314        if node.must_be_first and len(nodelist):
     315            raise TemplateSyntaxError, "%r must be the first Node on the template." % node
    314316        nodelist.append(node)
    315317
    316318    def enter_command(self, command, token):
     
    780782        return current
    781783
    782784class Node(object):
     785    # Set this to True if the node must be the first on a NodeList.
     786    must_be_first = False
     787
    783788    def render(self, context):
    784789        "Return the node rendered as a string"
    785790        pass
  • django/template/loader_tags.py

     
    3737            self.parent = BlockNode(self.name, nodelist)
    3838
    3939class ExtendsNode(Node):
     40    must_be_first = True
     41
    4042    def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
    4143        self.nodelist = nodelist
    4244        self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
    4345        self.template_dirs = template_dirs
    4446
     47    def __repr__(self):
     48        return '<ExtendsNode: %s>' % self.parent_name
     49
    4550    def get_parent(self, context):
    4651        if self.parent_name_expr:
    4752            self.parent_name = self.parent_name_expr.resolve(context)
Back to Top