def resolve_blocks(template, context):
try:<EOL><INDENT>blocks = context.render_context[BLOCK_CONTEXT_KEY]<EOL><DEDENT>except KeyError:<EOL><INDENT>blocks = context.render_context[BLOCK_CONTEXT_KEY] = BlockContext()<EOL><DEDENT>if isinstance(template, six.string_types):<EOL><INDENT>template = get_template(template)<EOL><DEDENT>template = getattr(template, '<STR_LIT>', template)<EOL>local_blocks = {<EOL>block.name: block<EOL>for block in template.nodelist.get_nodes_by_type(BlockNode)<EOL>}<EOL>blocks.add_blocks(local_blocks)<EOL>extends = template.nodelist.get_nodes_by_type(ExtendsNode)<EOL>if extends:<EOL><INDENT>extends_node = extends[<NUM_LIT:0>]<EOL>parent_template = extends_node.get_parent(context)<EOL>resolve_blocks(parent_template, context)<EOL><DEDENT>return blocks<EOL>
Return a BlockContext instance of all the {% block %} tags in the template.

If template is a string, it will be resolved through get_template