Extends the dictionary `blocks` with *new* blocks in the parent node (recursive)

    :param extend_node: The ``{% extends .. %}`` node object.
    :type extend_node: ExtendsNode
    :param blocks: dict of all block names found in the template.
    :type blocks: dict

def _extend_blocks(extend_node, blocks, context):
    """
    Extends the dictionary `blocks` with *new* blocks in the parent node (recursive)

    :param extend_node: The ``{% extends .. %}`` node object.
    :type extend_node: ExtendsNode
    :param blocks: dict of all block names found in the template.
    :type blocks: dict
    """
    try:
        # This needs a fresh parent context, or it will detection recursion in Django 1.9+,
        # and thus skip the base template, which is already loaded.
        parent = extend_node.get_parent(_get_extend_context(context))
    except TemplateSyntaxError:
        if _is_variable_extends(extend_node):
            # we don't support variable extensions unless they have a default.
            return
        else:
            raise

    # Search for new blocks
    for parent_block in parent.nodelist.get_nodes_by_type(BlockNode):
        if not parent_block.name in blocks:
            blocks[parent_block.name] = parent_block
        else:
            # set this node as the super node (for {{ block.super }})
            block = blocks[parent_block.name]
            seen_supers = []
            while hasattr(block.parent, 'nodelist') and block.parent not in seen_supers:
                seen_supers.append(block.parent)
                block = block.parent
            block.parent = parent_block

    # search for further ExtendsNodes in the extended template
    # There is only one extend block in a template (Django checks for this).
    parent_extends = parent.nodelist.get_nodes_by_type(ExtendsNode)
    if parent_extends:
        _extend_blocks(parent_extends[0], blocks, context)