[Zope] getting at ZCatalog data object in Python

Tom P. Allred tom at allreddata.com
Mon Nov 17 15:59:36 EST 2003


Thanks for the reply.  It gave me an error in the ZPT (TypeError: sequence
index must be integer ) when I tried to use it as in your example, but
worked when I assigned it to a variable and returned that instead.  BTW,
only one data object will get returned per query.

Here is my test ZPT that pulls the client's last name from the data object:
<html>
  <body tal:define="client container/CatalogClientTest2">
       <p><b>Client Name: </b>
        <span tal:replace="client/cl_lastname">ClientName</span>
     </p>
  </body>
</html>

Here is my modified (working) script based on your suggestion:
for x in context.Catalog(datatype='client',id='12346'):
  drec = x.getObject()
return drec

Just out of curiosity, can you tell me why the following doesn't work
(Script Error: LazyMap instance has no attribute 'getObject') since only one
catalog item is the result of the query?

zcat = context.Catalog(datatype='client',id='12346')
drec = zcat.getObject()
return drec

Thanks,
Tom P. Allred, MCSE, RHCE, CCNA
Allred Data Consulting, Inc.
888-381-0611
www.AllredData.com
Tom at AllredData.com


-----Original Message-----
From: zope-bounces+tom=allreddata.com at zope.org
[mailto:zope-bounces+tom=allreddata.com at zope.org]On Behalf Of Dieter
Maurer
Sent: Monday, November 17, 2003 1:57 PM
To: tom at allreddata.com
Cc: zope at zope.org
Subject: Re: [Zope] getting at ZCatalog data object in Python


Tom P. Allred wrote at 2003-11-16 17:06 -0500:
 > I'd like to return the data object a ZCatalog entry points to so a ZPT
can
 > display the data.  Currently I'm doing it in a 2-step process where a
Python
 > script finds/returns the catalog entry and the ZPT uses getObject to
define
 > a variable to get at the actual data.  What I want to do is have the
Python
 > script find the catalog entry then return the actual data object to the
ZPT.

The Python Script can use "getObject" in the same way as the ZPT, e.g.

    ....
    return [x.getObject() for x in Catalog(queryspec)]


Note, that "getObject" is a potentially expensive operation.
You would not like to call it on hundreds/thousands of objects
(especially not, when you later use only a handful).

--
Dieter

_______________________________________________
Zope maillist  -  Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )




More information about the Zope mailing list