Opened 19 years ago

Closed 19 years ago

Last modified 17 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: no UI/UX: no

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 by santagada@…, 19 years ago

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 by Clint Ecker <clintecker@…>, 19 years ago

priority: lownormal

comment:3 by Clint Ecker <clintecker@…>, 19 years ago

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

comment:4 by Jacob, 19 years ago

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 by anonymous, 18 years ago

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