Ticket #10644: 10644_ifchanged.1.diff

File 10644_ifchanged.1.diff, 1.6 KB (added by Antti Kaihola, 16 years ago)

Patch: stop {% ifchanged %} from changing context, includes test

  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 0911309..3606258 100644
    a b class IfChangedNode(Node):  
    189189        if compare_to != self._last_seen:
    190190            firstloop = (self._last_seen == None)
    191191            self._last_seen = compare_to
    192             context.push()
    193             context['ifchanged'] = {'firstloop': firstloop}
    194192            content = self.nodelist_true.render(context)
    195             context.pop()
    196193            return content
    197194        elif self.nodelist_false:
    198195            return self.nodelist_false.render(context)
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 4f7db62..5d48acf 100644
    a b class Templates(unittest.TestCase):  
    598598
    599599            'ifchanged-else04': ('{% for id in ids %}{% ifchanged %}***{{ id }}*{% else %}...{% endifchanged %}{{ forloop.counter }}{% endfor %}', {'ids': [1,1,2,2,2,3,4]}, '***1*1...2***2*3...4...5***3*6***4*7'),
    600600
     601            # Should not pollute context in undocumented ways.
     602            'ifchanged-context01': ('{% for n in num %}{% ifchanged %}{{ n }}{{ ifchanged }}{% endifchanged %}{% endfor %}', {'num': (1,2,3), 'ifchanged': '.'}, '1.2.3.'),
     603
    601604            ### IFEQUAL TAG ###########################################################
    602605            'ifequal01': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 2}, ""),
    603606            'ifequal02': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 1}, "yes"),
Back to Top