[Zope-dev] Re: TALES idea: tuple unpacking

Tino Wildenhain tino@wildenhain.de
Wed, 23 Jul 2003 16:12:58 +0200


Shane Hathaway wrote:
> Philipp von Weitershausen wrote:
> 
>> I agree that it is 'yucky', but I have to disagree with your proposed
>> solution. I would rather suggest making TALES aware of integer indexes
>> for sequences. Example::
>>
>>   <tal:block repeat="user_files here/listFilesByUser">
>>     User: <tal:dummy replace="user_files/0" />
>>     File: <tal:dummy replace="user_files/1" />
>>   </tal:block>
> 
> 
> Here's the way I'd like to spell it:
> 
>   <div tal:repeat="user_files here/listFilesByUser">
>     User: <span tal:replace="user_files/int:0" />
>     File: <span tal:replace="user_files/int:1" />
>   </div>
> 
> Literally, "user_files/int:0" says "get item 0 of user_files, 
> interpreting '0' as an integer".  Technically, this could be interpreted 
> as "get the attribute named 0 or item 0", but an attribute name must be 
> a string, so implicitly it really just says "get item 0".
> 
> We've come up with a number of generally useful prefixes, BTW.  Off the 
> top of my head:
> 
> call:   -- Call a named method
> int:    -- Look up an item by index
> format: -- Perform simple formatting operations like "format:money"
> zope:   -- Access a big Zope API
> 
> It sure would be nice to have these prefixes, both in Zope 2 and Zope 3.

Hm. But then would we not be better of using python: expressions in the 
first place? Seems to save a lot of typing.
I'd better like to build up lazy complex objects with python scripts
to pass to ZPT, I think this would make more sense.
Imagine instead of returning lists of dictionaries with all precalculated
values you return list of objects with real methods to calculate 
attributes on demand. (Yes, sounds like ZPatterns, but may be
a more easy interface)

Regards
Tino