#2454 closed enhancement (fixed)
[patch] for-loops reset state of inner ifchanged
Reported by: | 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)
Change History (8)
by , 18 years ago
Attachment: | for-reset-ifchanged.diff added |
---|
by , 18 years ago
Attachment: | ifchanged-demo1.png added |
---|
by , 18 years ago
Attachment: | for-reset-ifchanged-demo1.png added |
---|
Modified output where for-loop resets stated of inner ifchanged
by , 18 years ago
Attachment: | competition_list.html added |
---|
The used template-snippet (for explaination only)
comment:1 by , 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 , 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 , 18 years ago
Attachment: | for-reset-ifchanged.2.diff added |
---|
Solution which handles all in ifchanged-implementation
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Normal output