Ticket #6646: 6646.2.diff

File 6646.2.diff, 3.0 KB (added by SmileyChris, 6 years ago)
  • django/template/loader_tags.py

    ### Eclipse Workspace Patch 1.0
    #P Django trunk
     
    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.
     
    106106                raise
    107107            self.template = None
    108108
     109    def _get_template(self):
     110        return self._template
     111
     112    def _set_template(self, template):
     113        """
     114        Set the node's ``template`` attribute, and also update the node's
     115        ``nodelist`` attribute (used by ``Node.get_nodes_by_type()``).
     116        """
     117        self._template = template
     118        if template:
     119            self.nodelist = self.template.nodelist
     120        elif hasattr(self, 'nodelist'):
     121            del self.nodelist
     122
     123    template = property(_get_template, _set_template)
     124
    109125    def render(self, context):
    110126        if self.template:
    111127            return self.template.render(context)
  • tests/regressiontests/templates/tests.py

     
    802802            # Inheritance from a template with a space in its name should work.
    803803            'inheritance29': ("{% extends 'inheritance 28' %}", {}, '!'),
    804804
     805            # Setup a template to be included by base template
     806            'inheritance30': ("{% block included %}2{% endblock %}", {}, '2'),
     807
     808            # Setup a base template with an include
     809            'inheritance31': ("1{% include 'inheritance30' %}3", {}, '123'),
     810
     811            # Inheritance with overriding a block included by the parent
     812            'inheritance32': ("{% extends 'inheritance31' %}{% block included %}&{% endblock %}", {}, '1&3'),
     813
     814            # Setup a template to be included by child template
     815            'inheritance33': ("{% block included %}_{% endblock %}", {}, '_'),
     816
     817            # Inheritance with overriding a block through an include
     818            'inheritance34': ("{% extends 'inheritance30' %}{% include 'inheritance33' %}", {}, '_'),
     819
     820            # Inheritance with overriding a block included by the parent through an include in the child template (combine 32+34)
     821            'inheritance35': ("{% extends 'inheritance31' %}{% include 'inheritance33' %}", {}, '1_3'),
     822
    805823            ### I18N ##################################################################
    806824
    807825            # {% spaceless %} tag
Back to Top