[ZPT] select option question

Wade Leftwich wade@lightlink.com
Fri, 1 Jun 2001 09:45:10 -0400


Well, I hit the Send key too fast. Of course I meant to say:

dict = {}
for rec in recset:
    dict[rec[fieldname]] = 1

> -----Original Message-----
> From: Wade Leftwich [mailto:wade@lightlink.com]
> Sent: Friday, June 01, 2001 9:38 AM
> To: zpt@zope.org
> Cc: daniel.a.fulton@delphiauto.com
> Subject: [ZPT] select option question
> 
> 
> >is this the best way to do an <select><option selected> tag set? 
> it works but I
> >thought there might
> >be a shorter route that I missed.
> 
> I do it in a Python script, like this:
> 
> ## Script (Python) "ischecked"
> ##parameters=recset,fieldname
> 
> dict = {}
> for rec in recset:
>     dict[fieldname] = 1
> 
> def ischecked(item, dict=dict):
>     if dict.has_key(item):
>         return 'checked'
>     else:
>         return ''
> 
> return ischecked
> 
> ########
> 
> 
> Then your template can say something like this:
> 
> <span tal:define="global ischecked 
> python:container.ischecked(myquerysesults, 'Id')" tal:replace="nothing"/>
> <span tal:repeat="row otherqueryresults">
>  <input type="checkbox" name="id"
>                  tal:define="thisid row/Id"
>                  tal:attributes="value thisid; 
>                                  checked python:ischecked(thisid)" /> 
> </span>
> 
> -----------------------------
> If you find yourself doing this a lot, you could make a top-level 
> script and build in some generality, to deal with 'checked' 
> values in querystrings, lists, tokens, etc.
> ------------------------------
> 
> Wade Leftwich
> Ithaca, NY
> 
> 
>