Django

Code

Ticket #6322 (closed: fixed)

Opened 1 year ago

Last modified 5 months ago

ifchanged doesn't properly reset itself if not evaluated each time through the loop

Reported by: nedbatchelder Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by adrian)

When using ifchanged in a doubly-nested loop, the value is only reset to None on the inner loop's first iteration. But if the ifchanged tag is inside another conditional, it may not be evaluated on the first iteration. This can mean the value isn't properly reset:

    {% for data in datalist %}
        {% for c,d in data %}
            {% if c %}
                {% ifchanged %}{{ d }}{% endifchanged %}
            {% endif %}
        {% endfor %}
    {% endfor %}

The fix is to not examine forloop.first explicitly, but to annotate the forloop context.

Attachments

ifchanged.diff (2.3 kB) - added by nedbatchelder on 01/05/08 14:18:57.
the patch!

Change History

01/05/08 14:18:57 changed by nedbatchelder

  • attachment ifchanged.diff added.

the patch!

06/08/08 07:31:18 changed by jacob

  • needs_better_patch changed.
  • stage changed from Unreviewed to Ready for checkin.
  • needs_tests changed.
  • needs_docs changed.

06/25/08 23:12:40 changed by adrian

  • description changed.

Fixed formatting in description.

06/25/08 23:30:06 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [7752]) Fixed #6322 -- Fixed bug in 'ifchanged' template tag where it wasn't resetting itself properly in some cases. Thanks, nedbatchelder


Add/Change #6322 (ifchanged doesn't properly reset itself if not evaluated each time through the loop)




Change Properties
Action