Ticket #6322: ifchanged.diff

File ifchanged.diff, 2.3 KB (added by Ned Batchelder, 16 years ago)

the patch!

  • django/template/defaulttags.py

     
    162162        self.nodelist = nodelist
    163163        self._last_seen = None
    164164        self._varlist = map(Variable, varlist)
    165 
     165        self._id = str(id(self))
     166       
    166167    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']:
    168169            self._last_seen = None
     170            context['forloop'][self._id] = self
    169171        try:
    170172            if self._varlist:
    171173                # Consider multiple parameters.  This automatically behaves
  • tests/regressiontests/templates/tests.py

     
    544544            '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'),
    545545            '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'),
    546546
     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
    547555            # Test one parameter given to ifchanged.
    548556            'ifchanged-param01': ('{% for n in num %}{% ifchanged n %}..{% endifchanged %}{{ n }}{% endfor %}', { 'num': (1,2,3) }, '..1..2..3'),
    549557            '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'),
Back to Top