Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Fixed #13414 - QuerySet API ref wrong sql equivalent in __yea…

…r lookup example

Thanks to idle for report and patch

Backport of [13690] from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13693 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 79d92067119569e95f2a0aa6827586d83ab88eda 1 parent a537235
@spookylukey spookylukey authored
View
11 django/template/defaulttags.py
@@ -157,15 +157,22 @@ def render(self, context):
loop_dict['first'] = (i == 0)
loop_dict['last'] = (i == len_values - 1)
+ pop_context = False
if unpack:
# If there are multiple loop variables, unpack the item into
# them.
- context.update(dict(zip(self.loopvars, item)))
+ try:
+ unpacked_vars = dict(zip(self.loopvars, item))
+ except TypeError:
+ pass
+ else:
+ pop_context = True
+ context.update(unpacked_vars)
else:
context[self.loopvars[0]] = item
for node in self.nodelist_loop:
nodelist.append(node.render(context))
- if unpack:
+ if pop_context:
# The loop variables were pushed on to the context so pop them
# off again. This is necessary because the tag lets the length
# of loopvars differ to the length of each set of items and we
View
1  tests/regressiontests/templates/tests.py
@@ -701,6 +701,7 @@ def get_template_tests(self):
'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/")),
'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/")),
'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/")),
+ 'for-tag-unpack14': ("{% for x,y in items %}{{ x }}:{{ y }}/{% endfor %}", {"items": (1, 2)}, (":/:/", "INVALID:INVALID/INVALID:INVALID/")),
'for-tag-empty01': ("{% for val in values %}{{ val }}{% empty %}empty text{% endfor %}", {"values": [1, 2, 3]}, "123"),
'for-tag-empty02': ("{% for val in values %}{{ val }}{% empty %}values array empty{% endfor %}", {"values": []}, "values array empty"),
'for-tag-empty03': ("{% for val in values %}{{ val }}{% empty %}values array not found{% endfor %}", {}, "values array not found"),

0 comments on commit 79d9206

Please sign in to comment.
Something went wrong with that request. Please try again.