Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2454 closed enhancement (fixed)

[patch] for-loops reset state of inner ifchanged

Reported by: dummy@… Owned by: Adrian Holovaty
Component: Template system Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

I have a use-case of ifchanged which maybe worth to talk about:

Normally ifchanged is placed in a for-loop (or other kind of loop). If this loop is enclosed by an other loop the state of the ifchanged in the inner loop maybe incorrect respective to the outer loop.

Since I'm not really good at explaining this I made two hardcopies which should explain it better. I have a template which display tournaments in the outer loop and within the tournaments a loop of competitions with a competition-date which should only rendered if the competition-date has changed regarding the previous value.

Normally this result in the output of ifchanged-demo1.png . Please look after 'Sparda-Bank West Mannschaftsturnier, Bochum, 16./17.9.2006' In the next line the date 16.09.2006 is missing.

With the patch the result would be shown as in for-reset-ifchanged-demo1.png.

This maybe break some of the normal usecase of ifchanged, so this needs to be reviewed and discussed forther.

Regards,
Dirk

Attachments (5)

for-reset-ifchanged.diff (922 bytes ) - added by dummy@… 18 years ago.
ifchanged-demo1.png (66.2 KB ) - added by dummy@… 18 years ago.
Normal output
for-reset-ifchanged-demo1.png (66.8 KB ) - added by dummy@… 18 years ago.
Modified output where for-loop resets stated of inner ifchanged
competition_list.html (752 bytes ) - added by dummy@… 18 years ago.
The used template-snippet (for explaination only)
for-reset-ifchanged.2.diff (559 bytes ) - added by dummy@… 18 years ago.
Solution which handles all in ifchanged-implementation

Download all attachments as: .zip

Change History (8)

by dummy@…, 18 years ago

Attachment: for-reset-ifchanged.diff added

by dummy@…, 18 years ago

Attachment: ifchanged-demo1.png added

Normal output

by dummy@…, 18 years ago

Modified output where for-loop resets stated of inner ifchanged

by dummy@…, 18 years ago

Attachment: competition_list.html added

The used template-snippet (for explaination only)

comment:1 by Adrian Holovaty, 18 years ago

Great report! Modifying the behavior of the for tag is a bit hackish, though. Ideally the solution would only modify the implementation of ifchanged. Can you come up with a way of doing that?

comment:2 by dummy@…, 18 years ago

I tried to do this first in the implementation of ifchanged, but until now I didn't understand the way django is processing the nodes and how the ifchanged-Node can see that a new for-loop has startet ?

by dummy@…, 18 years ago

Attachment: for-reset-ifchanged.2.diff added

Solution which handles all in ifchanged-implementation

comment:3 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

(In [3800]) Fixed #2454 -- Make "ifchanged" tag work more predictably inside nested
for-loops. Thanks, dummy@….

Note: See TracTickets for help on using tickets.
Back to Top