Ticket #6646: 6646.diff

File 6646.diff, 3.0 KB (added by miracle2k, 6 years ago)

includes tests

  • django/template/loader_tags.py

    diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
    index 38b2fff..3239abd 100644
    a b class ExtendsNode(Node): 
    8787                        if isinstance(node, ExtendsNode):
    8888                            node.nodelist.append(block_node)
    8989                        # Extends must be the first non-text node, so once you find
    90                         # the first non-text node you can stop looking. 
     90                        # the first non-text node you can stop looking.
    9191                        break
    9292            else:
    9393                # Keep any existing parents and add a new one. Used by BlockNode.
    class ConstantIncludeNode(Node): 
    106106                raise
    107107            self.template = None
    108108
     109    @property
     110    def nodelist(self):
     111        if not self.template:
     112            return None
     113        return self.template.nodelist
     114
    109115    def render(self, context):
    110116        if self.template:
    111117            return self.template.render(context)
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index c69e7cd..933f7e8 100644
    a b class Templates(unittest.TestCase): 
    372372
    373373            # Numbers as filter arguments should work
    374374            'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."),
    375            
     375
    376376            #filters should accept empty string constants
    377377            'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""),
    378378
    class Templates(unittest.TestCase): 
    732732            # Inheritance from a template that doesn't have any blocks
    733733            'inheritance27': ("{% extends 'inheritance26' %}", {}, 'no tags'),
    734734
     735            # Setup a template to be included by base template
     736            'inheritance28': ("{% block included %}2{% endblock %}", {}, '2'),
     737
     738            # Setup a base template with an include
     739            'inheritance29': ("1{% include 'inheritance28' %}3", {}, '123'),
     740
     741            # Inheritance with overriding a block included by the parent
     742            'inheritance30': ("{% extends 'inheritance29' %}{% block included %}&{% endblock %}", {}, '1&3'),
     743
     744            # Setup a template to be included by child template
     745            'inheritance31': ("{% block included %}_{% endblock %}", {}, '_'),
     746
     747            # Inheritance with overriding a block through an include
     748            'inheritance32': ("{% extends 'inheritance28' %}{% include 'inheritance31' %}", {}, '_'),
     749
     750            # Inheritance with overriding a block included by the parent through an include in the child template (combine 30+32)
     751            'inheritance33': ("{% extends 'inheritance29' %}{% include 'inheritance31' %}", {}, '1_3'),
     752
    735753            ### I18N ##################################################################
    736754
    737755            # {% spaceless %} tag
Back to Top