Ticket #6232: 6232.diff

File 6232.diff, 2.7 KB (added by Chris Beaven, 17 years ago)

enhancement, with test

  • django/template/defaulttags.py

     
    163163    def __init__(self, nodelist, *varlist):
    164164        self.nodelist = nodelist
    165165        self._last_seen = None
    166         self._varlist = map(Variable, varlist)
     166        self._varlist = varlist
    167167
    168168    def render(self, context):
    169169        if 'forloop' in context and context['forloop']['first']:
     
    805805    bits = token.contents.split()
    806806    nodelist = parser.parse(('endifchanged',))
    807807    parser.delete_first_token()
    808     return IfChangedNode(nodelist, *bits[1:])
     808    varlist = [parser.compile_filter(bit) for bit in bits[1:]]
     809    return IfChangedNode(nodelist, *varlist)
    809810ifchanged = register.tag(ifchanged)
    810811
    811812#@register.tag
  • tests/regressiontests/templates/tests.py

     
    552552            # Test a date+hour like construct, where the hour of the last day
    553553            # is the same but the date had changed, so print the hour anyway.
    554554            'ifchanged-param04': ('{% for d in days %}{% ifchanged %}{{ d.day }}{% endifchanged %}{% for h in d.hours %}{% ifchanged d h %}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}', {'days':[{'day':1, 'hours':[1,2,3]},{'day':2, 'hours':[3]},] }, '112323'),
    555 
    556555            # Logically the same as above, just written with explicit
    557556            # ifchanged for the day.
    558             'ifchanged-param04': ('{% for d in days %}{% ifchanged d.day %}{{ d.day }}{% endifchanged %}{% for h in d.hours %}{% ifchanged d.day h %}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}', {'days':[{'day':1, 'hours':[1,2,3]},{'day':2, 'hours':[3]},] }, '112323'),
     557            'ifchanged-param05': ('{% for d in days %}{% ifchanged d.day %}{{ d.day }}{% endifchanged %}{% for h in d.hours %}{% ifchanged d.day h %}{{ h }}{% endifchanged %}{% endfor %}{% endfor %}', {'days':[{'day':1, 'hours':[1,2,3]},{'day':2, 'hours':[3]},] }, '112323'),
    559558
     559            # Variables passed to ifchanged can have filters.
     560            'ifchanged-param06': ('{% for f in floats %}{% ifchanged f|floatformat:2 %}{{ f }}--{% endifchanged %}{% endfor %}', {'floats': [1.1, 1.1, 1.3, 1.305, 1.4] }, '1.1--1.3--1.4--'),
     561
    560562            ### IFEQUAL TAG ###########################################################
    561563            'ifequal01': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 2}, ""),
    562564            'ifequal02': ("{% ifequal a b %}yes{% endifequal %}", {"a": 1, "b": 1}, "yes"),
Back to Top