forloop internals should create a single context dictionary, rather than recreating it on each iteration
|Reported by:||Ned Batchelder||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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...