[ZPT] Re: Add 'parity' to repeat?

Charlie Clark charlie at begeistert.org
Wed Aug 27 19:11:01 EDT 2003


On 2003-08-27 at 17:34:10 [+0200], Evan Simpson wrote:
> Actually, it is!  From Wikipedia: "Parity is the attribute of a value 
> describing whether it is even or odd. For example, the number 7 has odd 
> parity and the number 20 has even parity."
> 
> While I agree that "even" and "odd" aren't very expressive by themselves, 
> I still think that it's better to be able to write something like 
> "string:${repeat/row/parity)_table_row" than the usual 
> python-expression-with-test.

Yuck, is my initial response. I guess I'm allergic to "string:$" which just 
causes problems in my ZPTs and I only use very sparingly. In a curious way 
this suggestions reminds me of our recent discussion about "tal:if / else". 
It might be a nice feature which finds a lot of use for some people but is 
dangerously close to obscurity (who else is going to have to reach for the 
dictionary every time they see this?) for the rest of us; ie. it's feature 
creep. The basic feature is "index % n" where n is variable but limited to 
1 or 2 for this. I have a need for a more generic case so this change would 
not help me.

<tr tal:attributes="class python: test(repeat.row.number % n, 'highlight', 
'non-highlight')">

is as concise and explicit as I need it. Anything else can be done via 
dictionary dispatching.

<table tal:define="classes python:{'1':'red', '2':'green', '3':'blue'}">
<tr tal:attributes="class python:classes[string(repeat.row.number)]"></tr>
</table>

At least I think that should work: it adds power but maintains clarity. 
Comments appreciated.

***
By the way thanx very much for your private explanation of namespaces. 
TALES blocks then are like Python functions?

def a():
	x = 1
	def b():
		x = x +1  # reassign x locally based.

Charlie



More information about the ZPT mailing list