Translating DTML into Python Script
Hi all, I would like to translate the following piece of DTML code into Python Script: <dtml-in "objectValues('Folder')"> <a href="<dtml-var id>"><dtml-var title_or_id></a><br> </dtml-in> What I would like to achieve is to loop through the objects returned by my Python Script: <dtml-in MyPythonScript> <a href="<dtml-var id>"><dtml-var title_or_id></a><br> </dtml-in> This is what I have tried so far on the Python side: objlist=[] for obj in context.objectValues('Folder'): objlist.append(obj) return objlist But when I try to loop through these results I get the following error: Error Type: AttributeError Error Value: __getitem__ I have also tried appending obj.id to the objlist, but that didn't solve the problem either. Do I have to return objects in a certain format/type before I can loop through it with DTML? The reason I would like to return my objects with Python is so that I can implement some logic as to what objects are returned, eg. only return DTML Documents that have id's containing certain characters etc. Thanks a lot, Andreas.
On Mon, 11 Jun 2001, Andreas Pauley wrote:
But when I try to loop through these results I get the following error:
Error Type: AttributeError Error Value: __getitem__
Try this for me: <dtml-in MyPythonScript> <dtml-var "_['sequence-item']"> </dtml-in> and look at what is returned.
It works now, thanks. It seems that with me trying everything I can think of, I have at some stage typed: <dtml-in "MyPythonScript"> I can see now that there's a big difference between the quotes and the no-quotes version. I'm not sure exactly when you would use quotes and when not, but at least I'll know to look for something like this next time. Thanks again, Andreas. Erik Enge wrote:
On Mon, 11 Jun 2001, Andreas Pauley wrote:
But when I try to loop through these results I get the following error:
Error Type: AttributeError Error Value: __getitem__
Try this for me:
<dtml-in MyPythonScript> <dtml-var "_['sequence-item']"> </dtml-in>
and look at what is returned.
The quotes thing is a legacy issue, I think... The following two are AFAIK identical: <dtml-in "MyPythonScript"> <dtml-in expr="MyPythonScript"> Removing the quotes causes Zope to call the object rather than just obtain a reference to it (er, I think ;) Dan _________________________________________________________________ Daniel Fairs | daniel.fairs@spiderplant.net | www.spiderplant.net
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Andreas Pauley Sent: 11 June 2001 13:32 To: Erik Enge; Zope Subject: Re: [Zope] Translating DTML into Python Script
It works now, thanks.
It seems that with me trying everything I can think of, I have at some stage typed: <dtml-in "MyPythonScript">
I can see now that there's a big difference between the quotes and the no-quotes version. I'm not sure exactly when you would use quotes and when not, but at least I'll know to look for something like this next time.
Thanks again, Andreas.
Erik Enge wrote:
On Mon, 11 Jun 2001, Andreas Pauley wrote:
But when I try to loop through these results I get the
following error:
Error Type: AttributeError Error Value: __getitem__
Try this for me:
<dtml-in MyPythonScript> <dtml-var "_['sequence-item']"> </dtml-in>
and look at what is returned.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Andreas Pauley -
Daniel Fairs -
Erik Enge