Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #6322 -- Fixed bug in 'ifchanged' template tag where it wasn't …

…resetting itself properly in some cases. Thanks, nedbatchelder

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7752 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dbde7fc8b0932a169b8319dc597433aef1cb9520 1 parent 65437a9
@adrianholovaty adrianholovaty authored
View
4 django/template/defaulttags.py
@@ -162,10 +162,12 @@ def __init__(self, nodelist, *varlist):
self.nodelist = nodelist
self._last_seen = None
self._varlist = map(Variable, varlist)
+ self._id = str(id(self))
def render(self, context):
- if 'forloop' in context and context['forloop']['first']:
+ if 'forloop' in context and self._id not in context['forloop']:
self._last_seen = None
+ context['forloop'][self._id] = 1
try:
if self._varlist:
# Consider multiple parameters. This automatically behaves
View
6 tests/regressiontests/templates/tests.py
@@ -135,8 +135,7 @@ def test_templates(self):
# Quickly check that we aren't accidentally using a name in both
# template and filter tests.
- overlapping_names = [name for name in filter_tests if name in
- template_tests]
+ overlapping_names = [name for name in filter_tests if name in template_tests]
assert not overlapping_names, 'Duplicate test name(s): %s' % ', '.join(overlapping_names)
template_tests.update(filter_tests)
@@ -159,7 +158,7 @@ def test_template_loader(template_name, template_dirs=None):
# Turn TEMPLATE_DEBUG off, because tests assume that.
old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
- # Set TEMPLATE_STRING_IF_INVALID to a known string
+ # Set TEMPLATE_STRING_IF_INVALID to a known string.
old_invalid = settings.TEMPLATE_STRING_IF_INVALID
expected_invalid_str = 'INVALID'
@@ -549,6 +548,7 @@ def get_template_tests(self):
'ifchanged05': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', {'num': (1, 1, 1), 'numx': (1, 2, 3)}, '1123123123'),
'ifchanged06': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', {'num': (1, 1, 1), 'numx': (2, 2, 2)}, '1222'),
'ifchanged07': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% for y in numy %}{% ifchanged %}{{ y }}{% endifchanged %}{% endfor %}{% endfor %}{% endfor %}', {'num': (1, 1, 1), 'numx': (2, 2, 2), 'numy': (3, 3, 3)}, '1233323332333'),
+ 'ifchanged08': ('{% for data in datalist %}{% for c,d in data %}{% if c %}{% ifchanged %}{{ d }}{% endifchanged %}{% endif %}{% endfor %}{% endfor %}', {'datalist': [[(1, 'a'), (1, 'a'), (0, 'b'), (1, 'c')], [(0, 'a'), (1, 'c'), (1, 'd'), (1, 'd'), (0, 'e')]]}, 'accd'),
# Test one parameter given to ifchanged.
'ifchanged-param01': ('{% for n in num %}{% ifchanged n %}..{% endifchanged %}{{ n }}{% endfor %}', { 'num': (1,2,3) }, '..1..2..3'),
Please sign in to comment.
Something went wrong with that request. Please try again.