[ZPT] Re: [Zope] ZPT: How do I see if something is in a sequence?

alan runyan alan runyan" <runyaga@runyaga.com
Wed, 15 Aug 2001 10:31:17 -0500


Evan I greatly appreciate your response to my 2 inqueries.  I hope to spur
more recipe devleopment on zopelabs using PageTemplates and #irc support so
we can have more examples available to the community.

> If you're using the most recent release of ZPT, you can pre-filter the
> list, like so:
>
> <select name="moderator_ids:list" size="5" multiple
>   tal:define="filter nocall:modules/ZTUtils/LazyFilter;
>               members container/portal_membership/listMembers">
>    <option tal:repeat="member python:filter(members, lambda
> x:'Moderator' in x.helplink_roles)"
>            tal:content="member/getUserName">memberid
>    </option>
> </select>

wow.  that definetly could explode a designers head ;)  need to get head
around PageTemplates before I dive into ZTUtils.  I have an adversion to
lambda as it seems to make people who are new to python scratch their head.
but I'm going to go look at the ZTUtils to see what goodies are waiting for
me.

>
> All of this logic could be bundled up in a Script, too, like so:
>
> ## Script (Python) "getModerators"
> moderators = []
> for user in container.portal_membership.listMembers():
>    if 'Moderator' in user.helplink_roles:
>      moderators.append(user)
> return moderators
> # End Script
>
> <select name="moderator_ids:list" size="5" multiple>
>    <option tal:repeat="member container/getModerators"
>            tal:content="member/getUserName">memberid
>    </option>
> </select>

I agree this is much nicer, but since I'm doing all this TTW I try to keep
the Script(Python) explosion down to a minimal.  I posted this up on
zopelabs, as how to change Custom Properties of a Member object.  I am just
still getting use to PageTemplates.  The error messages seemed a bit terse.
Maybe that is just me.  I was getting Undefined's, so I should have known to
put repeat in <DIV>.  works beautifully.  I'm moving to PageTemplates
exclusively.  just having a hard time adjusting the HTML tags being block
delimiters  instead of the explicit <dtml-if></dtml-if> or <% %>.

~runyaga