Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#295 closed defect (fixed)

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

Reported by: Clint Ecker <clintecker@…> Owned by: Adrian Holovaty
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),

Change History (5)

comment:1 Changed 11 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 11 years ago by Clint Ecker <clintecker@…>

priority: lownormal

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

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

comment:4 Changed 11 years ago by Jacob

Resolution: fixed
Status: newclosed

(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 10 years ago by anonymous

Component: Template systemdjango-admin.py
priority: normalhigh
Severity: normalmajor
Summary: [patch] Add reverse counter variables to template "for loops"[patch] Add reverse counter variables to template &#34;for loops&#34;
Type: enhancementdefect
Version: 0.9
Note: See TracTickets for help on using tickets.
Back to Top