Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#295 closed defect (fixed)

[patch] Add reverse counter variables to template "for loops"

Reported by: Clint Ecker <clintecker@…> Owned by: adrian
Component: Core (Management commands) Version: 0.90
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I had a need to iterate backwards through the counter (i.e. 24,23,22,21...1) while displaying the items in a list in the proper order. I propose the addition of forloop.counterr and forloop.counter0r variables to complement forloop.counter and forloop.counter0.

It's a simple patch and I've inlcluded it here:

--- django/core/defaulttags.py    (revision 453)
+++ django/core/defaulttags.py   (working copy)
@@ -97,6 +97,8 @@
                 # shortcuts for current loop iteration number
                 'counter0': i,
                 'counter': i+1,
+                'counterr': len(values)-i,
+                'counter0r' : len(values)-i-1,
                 # boolean values designating first and last times through loop
                 'first': (i == 0),
                 'last': (i == len_values - 1),

Attachments (0)

Change History (5)

comment:1 Changed 9 years ago by santagada@…

I think it should be named "revcounter" and "revcounter0" or maybe "invcounter". Just one letter of difference between the two would be prone to mistakes.

comment:2 Changed 9 years ago by Clint Ecker <clintecker@…>

  • priority changed from low to normal

comment:3 Changed 9 years ago by Clint Ecker <clintecker@…>

  • Summary changed from [patch] Add reverse counter variables to template for loops to [patch] Add reverse counter variables to template "for loops"

comment:4 Changed 9 years ago by jacob

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

(In [736]) Fixed #295 - added forloop.revcounter and forloop.revcounter0 variables to for loops. Also updated the docs and added unit tests to verify correct behavior. Thanks, Clint.

comment:5 Changed 8 years ago by anonymous

  • Component changed from Template system to django-admin.py
  • priority changed from normal to high
  • Severity changed from normal to major
  • Summary changed from [patch] Add reverse counter variables to template "for loops" to [patch] Add reverse counter variables to template &#34;for loops&#34;
  • Type changed from enhancement to defect
  • Version set to 0.9

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.