Ticket #16335: defaultdict_conversion.diff
File defaultdict_conversion.diff, 1.6 KB (added by , 13 years ago) |
---|
-
django/template/base.py
672 672 detail and shouldn't be called by external code. Use Variable.resolve() 673 673 instead. 674 674 """ 675 from collections import defaultdict 675 676 current = context 676 677 try: # catch-all for silent variable failures 677 678 for bit in self.lookups: 678 679 try: # dictionary lookup 680 if isinstance(current, defaultdict): 681 current = dict(current) 679 682 current = current[bit] 680 683 except (TypeError, AttributeError, KeyError): 681 684 try: # attribute lookup -
tests/regressiontests/templates/context.py
1 1 # coding: utf-8 2 from django.template import Context 2 from django.template import Context, Variable 3 3 from django.utils.unittest import TestCase 4 4 5 5 … … 14 14 self.assertEqual(c.pop(), {"a": 2}) 15 15 self.assertEqual(c["a"], 1) 16 16 self.assertEqual(c.get("foo", 42), 42) 17 def test_defaultdict_conversion(self): 18 from collections import defaultdict 19 dd = defaultdict(list) 20 dd['a'].extend([1, 2, 3, 4]) 21 dd['b'].extend([5, 6, 7, 8]) 22 context = Context({'dd': dd}) 23 var = Variable('dd.items') 24 self.assertEqual(dd.items(), var.resolve(context))