templetor for loops need odd and even functions like django

Bug #176751 reported by Aaron Swartz
2
Affects Status Importance Assigned to Milestone
web.py
Fix Released
High
Anand Chitipothu

Bug Description

There should be some way to get the n of a for loop and whether it's odd or even. I'm thinking something like:

$for r in rows:
    <tr class="${for.parity}row"><th>$for.n</th><td>$r.name</td></tr>

The variables available this way would ideally be:

$for.n: the iteration of the loop (1-indexed)
$for.n0: the iteration of the loop (0-indexed)
$for.first: True if first iteration
$for.last: True if last iteration
$for.odd: True if an odd iteration
$for.even: True if an even iteration
$for.parity: "odd" or "even" depending on which is true
$for.parent: the loop above this in nested loops

Revision history for this message
Aaron Swartz (aaronsw) wrote :

i can probably work on this if you can't do it

Changed in openlibrary:
assignee: nobody → anandology
importance: Undecided → High
status: New → Confirmed
Changed in webpy:
milestone: none → 0.3
Revision history for this message
Tommi (tommi+-deactivatedaccount) wrote :

What's the status with this?

Revision history for this message
Anand Chitipothu (anandology) wrote :

Since for is a keyword, I would prefer using forloop.xxx instead of for.xxx.

How about forloop.index instead of for.n?

Changed in webpy:
status: Confirmed → In Progress
Revision history for this message
Aaron Swartz (aaronsw) wrote : Re: [Bug 176751] Re: templetor for loops need odd and even functions like django

I was thinking it made sense to use a reserved word so that existing
variables wouldn't get clobbered. Also, I like the brevity. Maybe
$loop instead?

Why do you prefer index?

Revision history for this message
Anand Chitipothu (anandology) wrote :

On Wed, Jun 18, 2008 at 11:07 AM, Aaron Swartz <email address hidden> wrote:
> I was thinking it made sense to use a reserved word so that existing
> variables wouldn't get clobbered.
Since I am trying to generate python code from the template in my new
implementation, it will not work.

> Also, I like the brevity. Maybe $loop instead?

fine.

> Why do you prefer index?

n is typically used to indicate length of the list.

Revision history for this message
Aaron Swartz (aaronsw) wrote :

Fine.

Revision history for this message
Anand Chitipothu (anandology) wrote :

How about adding:

loop.length - length of the loop (n)
loop.revindex - reverse index (n to 1)
loop.revindex0 - reverse index (n-1 to 0)

Revision history for this message
Aaron Swartz (aaronsw) wrote : Re: [Bug 176751] Re: templetor for loops need odd and even functions like django

> loop.length - length of the loop (n)
> loop.revindex - reverse index (n to 1)
> loop.revindex0 - reverse index (n-1 to 0)

Sure.
--
[sent from my phone; excuse typos]

Changed in webpy:
status: In Progress → Fix Committed
Changed in webpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.