Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2454 closed enhancement (fixed)

[patch] for-loops reset state of inner ifchanged

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

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

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by dummy@…

Changed 8 years ago by dummy@…

Normal output

Changed 8 years ago by dummy@…

Modified output where for-loop resets stated of inner ifchanged

Changed 8 years ago by dummy@…

The used template-snippet (for explaination only)

comment:1 Changed 8 years ago by adrian

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 Changed 8 years ago by dummy@…

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 ?

Changed 8 years ago by dummy@…

Solution which handles all in ifchanged-implementation

comment:3 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.