Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2454 -- Make "ifchanged" tag work more predictably inside nested

for-loops. Thanks, dummy@habmalnefrage.de.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bd4c22be0b7c75ef8b6a1e623fdc2626f05ea194 1 parent 670e8ab
Malcolm Tredinnick authored September 23, 2006
1  AUTHORS
@@ -69,6 +69,7 @@ answer newbie questions, and generally made Django that much better:
69 69
     deric@monowerks.com
70 70
     dne@mayonnaise.net
71 71
     Maximillian Dornseif <md@hudora.de>
  72
+    dummy@habmalnefrage.de
72 73
     Jeremy Dunck <http://dunck.us/>
73 74
     Andy Dustman <farcepest@gmail.com>
74 75
     Clint Ecker
2  django/template/defaulttags.py
@@ -129,6 +129,8 @@ def __init__(self, nodelist):
129 129
         self._last_seen = None
130 130
 
131 131
     def render(self, context):
  132
+        if context.has_key('forloop') and context['forloop']['first']:
  133
+            self._last_seen = None
132 134
         content = self.nodelist.render(context)
133 135
         if content != self._last_seen:
134 136
             firstloop = (self._last_seen == None)
4  tests/regressiontests/templates/tests.py
@@ -305,6 +305,10 @@ def test_templates(self):
305 305
             'ifchanged01': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,2,3) }, '123'),
306 306
             'ifchanged02': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,1,3) }, '13'),
307 307
             'ifchanged03': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,1,1) }, '1'),
  308
+            'ifchanged04': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% for x in numx %}{% ifchanged %}{{ x }}{% endifchanged %}{% endfor %}{% endfor %}', { 'num': (1, 2, 3), 'numx': (2, 2, 2)}, '122232'),
  309
+            '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'),
  310
+            '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'),
  311
+            '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'),
308 312
 
309 313
             ### IFEQUAL TAG ###########################################################
310 314
             'ifequal01': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 2}, ""),

0 notes on commit bd4c22b

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