[Zope] DTML into Python for Formulator

cgreen cgreen@ttsg.com
Mon, 14 Jan 2002 10:07:38 -0500


Dieter;

Thanks for the reply.... after I posted the original question, I got off 
my lazy butt, searched a few sites, and
came up with this: (hmmm...... a new acronym, maybe -- GOYLA?? [Get Off 
Your Lazy A--])

results=[]
for object in context.objectValues('STX_Document'):
   if object.getProperty('topic') != '':
   if tuple not in results:
       results.append(object.topic)

   results.sort()
  
return results


as a python script, instead of the DTML method:

<dtml-call "REQUEST.set('tmp',{})">
<dtml-in 
expr="_.sequence.sort(PARENTS[0].objectValues(['STX_Document']), 
(('topic', 'nocase'), ('title', 'cmp'),) )">
<dtml-call "REQUEST['tmp'].update({topic:''})">
</dtml-in>
<dtml-in "REQUEST['tmp'].keys()">
<dtml-var sequence-item>
</dtml-in>

Just thought I'd share this for anyone following the thread.... I hate 
seeing questions asked in newsgroups without answers......

> cgreen writes:
>  > ... DTML object ...
>  > The values of the "topic" property are returned.  But when called as an 
>  > override method for a Formulator MultiListField, I get this error:
>  > 
>  > 
>  >             Zope Error
>  > 
>  >             Zope has encountered an error while publishing this resource.
>  > 
>  >             Error Type: NameError
>  >             Error Value: global name 'REQUEST' is not defined
> I guess, it is a standard error:
> 
>   Whenever DTML objects are called explicitly, they should
>   get 2 positional parameters. These parameters are necessary
>   to provide the context to the DTML object call.
> 
>   In your case, the context is obviously missing.
> 
> Please read the section "Calling DTML objects" in 
> 
>   <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
> 
> to learn more.
> 
> 
> Dieter
> 
> 
>