Ticket #13475: 13475.diff
File 13475.diff, 2.7 KB (added by , 15 years ago) |
---|
-
django/template/defaulttags.py
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 318ae5f..d629a69 100644
a b class ForNode(Node): 157 157 loop_dict['first'] = (i == 0) 158 158 loop_dict['last'] = (i == len_values - 1) 159 159 160 pop_context = False 160 161 if unpack: 161 162 # If there are multiple loop variables, unpack the item into 162 163 # them. 163 context.update(dict(zip(self.loopvars, item))) 164 try: 165 unpacked_vars = dict(zip(self.loopvars, item)) 166 except TypeError: 167 pass 168 else: 169 pop_context = True 170 context.update(unpacked_vars) 164 171 else: 165 172 context[self.loopvars[0]] = item 166 173 for node in self.nodelist_loop: 167 174 nodelist.append(node.render(context)) 168 if unpack:175 if pop_context: 169 176 # The loop variables were pushed on to the context so pop them 170 177 # off again. This is necessary because the tag lets the length 171 178 # of loopvars differ to the length of each set of items and we -
tests/regressiontests/templates/tests.py
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 5902e8d..8804839 100644
a b class Templates(unittest.TestCase): 690 690 'for-tag-unpack11': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1), ('two', 2))}, ("one:1,/two:2,/", "one:1,INVALID/two:2,INVALID/")), 691 691 'for-tag-unpack12': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1, 'carrot'), ('two', 2))}, ("one:1,carrot/two:2,/", "one:1,carrot/two:2,INVALID/")), 692 692 'for-tag-unpack13': ("{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}", {"items": (('one', 1, 'carrot'), ('two', 2, 'cheese'))}, ("one:1,carrot/two:2,cheese/", "one:1,carrot/two:2,cheese/")), 693 'for-tag-unpack14': ("{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}", {"items": (1, 2)}, (":/:/", "INVALID:INVALID/INVALID:INVALID/")), 693 694 'for-tag-empty01': ("{% for val in values %}{{ val }}{% empty %}empty text{% endfor %}", {"values": [1, 2, 3]}, "123"), 694 695 'for-tag-empty02': ("{% for val in values %}{{ val }}{% empty %}values array empty{% endfor %}", {"values": []}, "values array empty"), 695 696 'for-tag-empty03': ("{% for val in values %}{{ val }}{% empty %}values array not found{% endfor %}", {}, "values array not found"),