[Zope3-dev] Number of languages in Zope 3
Steve Alexander
steve@cat-box.net
Sat, 12 Apr 2003 11:57:45 +0200
A generator would fix this.
Chris Withers wrote:
> Hi Tres,
>
> In your example below, what are the preformance implications of
> iterating over the result list twice as opposed to just once?
>
> cheers,
>
> Chris
>
> Tres Seaver wrote:
>
>> In Zope3, that idiom would typically be replaced by an intermediate
>> method on the view class which did the underlying work. E.g., where in
>> Zope2 I might to something like:
>>
>> <div tal:repeat="snippet python:here.objectValues(['Some Type'])">
>> <h3 tal:conetnt="python:snippet.headline(version='Brief')">HEADLINE
>> >/h3>
>> <div tal:content="python:snippet.teaseText(maxwords=100)>TEASE</div>
>> </div>
>>
>> in Zope3 I would add a method to the view class which did the heavy
>> lifting:
>>
>> def getSnippetInfo(self):
>> results = []
>> for snippet in [x for x in self.context.values()
>> if ISnippet.isImplementedBy(x) ]:
>> results.append({'title' : snppet.headline(version='Brief'),
>> 'tease' : snippet.teaseText(maxWords=100)})
>> return results
>>
>> The template then becomes much clearer:
>>
>> <div tal:repeat="info context/getSnippetInfo">
>> <h3 tal:content="info/title">TITLE</h3>
>> <div tal:content="info/tease">TEASE</div>
>> </div>
>
>
>