Ticket #19846: 19846.diff

File 19846.diff, 1.4 KB (added by FunkyBob, 12 years ago)
  • django/template/loader_tags.py

    diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
    index d295d05..6dbe49f 100644
    a b from django.template.loader import get_template  
    55from django.utils.safestring import mark_safe
    66from django.utils import six
    77
     8from collections import defaultdict
     9
    810register = Library()
    911
    1012BLOCK_CONTEXT_KEY = 'block_context'
    class ExtendsError(Exception):  
    1517class BlockContext(object):
    1618    def __init__(self):
    1719        # Dictionary of FIFO queues.
    18         self.blocks = {}
     20        self.blocks = defaultdict(list)
    1921
    2022    def add_blocks(self, blocks):
    2123        for name, block in six.iteritems(blocks):
    22             if name in self.blocks:
    23                 self.blocks[name].insert(0, block)
    24             else:
    25                 self.blocks[name] = [block]
     24            self.blocks[name].insert(0, block)
    2625
    2726    def pop(self, name):
    2827        try:
    2928            return self.blocks[name].pop()
    30         except (IndexError, KeyError):
     29        except IndexError:
    3130            return None
    3231
    3332    def push(self, name, block):
    class BlockContext(object):  
    3635    def get_block(self, name):
    3736        try:
    3837            return self.blocks[name][-1]
    39         except (IndexError, KeyError):
     38        except IndexError:
    4039            return None
    4140
    4241class BlockNode(Node):
Back to Top