Ticket #6322: ifchanged.diff
File ifchanged.diff, 2.3 KB (added by , 17 years ago) |
---|
-
django/template/defaulttags.py
162 162 self.nodelist = nodelist 163 163 self._last_seen = None 164 164 self._varlist = map(Variable, varlist) 165 165 self._id = str(id(self)) 166 166 167 def render(self, context): 167 if 'forloop' in context and context['forloop']['first']:168 if 'forloop' in context and self._id not in context['forloop']: 168 169 self._last_seen = None 170 context['forloop'][self._id] = self 169 171 try: 170 172 if self._varlist: 171 173 # Consider multiple parameters. This automatically behaves -
tests/regressiontests/templates/tests.py
544 544 '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'), 545 545 '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'), 546 546 547 'ifchanged08': ( 548 '{% for data in datalist %}' 549 '{% for c,d in data %}' 550 '{% if c %}{% ifchanged %}{{ d }}{% endifchanged %}{% endif %}' 551 '{% endfor %}' 552 '{% endfor %}', 553 { 'datalist': [[(1,'a'),(1,'a'),(0,'b'),(1,'c')],[(0,'a'),(1,'c'),(1,'d'),(1,'d'),(0,'e')]] }, 'accd'), 554 547 555 # Test one parameter given to ifchanged. 548 556 'ifchanged-param01': ('{% for n in num %}{% ifchanged n %}..{% endifchanged %}{{ n }}{% endfor %}', { 'num': (1,2,3) }, '..1..2..3'), 549 557 'ifchanged-param02': ('{% for n in num %}{% for x in numx %}{% ifchanged n %}..{% endifchanged %}{{ x }}{% endfor %}{% endfor %}', { 'num': (1,2,3), 'numx': (5,6,7) }, '..567..567..567'),