Django

Code

Ticket #6295 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

forloop internals should create a single context dictionary, rather than recreating it on each iteration

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

Description

In this django-users thread (http://groups.google.com/group/django-users/browse_thread/thread/3c79d7e1df438c68) I asked how to make an iffirst tag. My first attempt at the tag was to maintain state in the contextforloop? dictionary. I found that it isn't not maintained between iterations. Malcolm chimed in with exactly the same intuition, and also found that it didn't work.

Looking at the code, there seems to be no good reason to re-make the dictionary each time.

This patch changes the code to keep the same dictionary for the life of the forloop, so that other tags can use the dictionary to maintain state.

I also added tests for forloop.first and forloop.last, which were never tested directly...

Attachments

forloop.diff (3.0 kB) - added by nedbatchelder on 01/01/08 14:27:19.
the patch!

Change History

01/01/08 14:27:19 changed by nedbatchelder

  • attachment forloop.diff added.

the patch!

01/01/08 23:02:20 changed by adrian

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to fixed.
  • needs_tests changed.
  • needs_docs changed.

(In [6981]) Fixed #6295 -- Made the {% for %} tag a bit more efficient by creating a single context dictionary rather than recreating it each time through the loop. Thanks, Ned Batchelder


Add/Change #6295 (forloop internals should create a single context dictionary, rather than recreating it on each iteration)




Change Properties
Action