Get Access to Object from its record in the ZCatalog
I'm pulling my hair out here. I'm sure the answer is simple. How can I get to properties of an object from its ZCatalog entry? I'm iterating through results, and want to do something special if the result is a record for a PDF file. I know how to check the file to see if its a PDF, but ZCatalog does not keep track of all the file contents. I know there is a way to resolve the record ID into the actual object, but I forget how and cannot find a reference to it. Thanks, Edward ---- For clarity, here is some of my code. I am looking for what to use instead of ?? zIndex_Catalog is my Catalog. zIndexFileItem is my CatalogAware wrapper ZClass for File. searchresults = list(context.zIndex_Catalog.searchResults(blah blah search params blah blah)) searchresults.sort( lambda x, y: cmp(x.title, y.title)) for result in searchresults: if ((??.meta_type == 'File') or (??.meta_type == 'zIndexFileItem')): if (??.getContentType == "application/pdf"): PDF Specific Code Here
Well, I'm new to this list, but I had a similar problem. I just stuck the meta_type, etc. in the catalog using additional Metadata. Afterally, the attributes you're referring to are small. Best Regards, -jj On Thu, Mar 06, 2003 at 03:30:01PM -0700, Edward Pollard wrote:
I'm pulling my hair out here. I'm sure the answer is simple.
How can I get to properties of an object from its ZCatalog entry?
I'm iterating through results, and want to do something special if the result is a record for a PDF file. I know how to check the file to see if its a PDF, but ZCatalog does not keep track of all the file contents. I know there is a way to resolve the record ID into the actual object, but I forget how and cannot find a reference to it.
Thanks,
Edward
---- For clarity, here is some of my code. I am looking for what to use instead of ?? zIndex_Catalog is my Catalog. zIndexFileItem is my CatalogAware wrapper ZClass for File.
searchresults = list(context.zIndex_Catalog.searchResults(blah blah search params blah blah)) searchresults.sort( lambda x, y: cmp(x.title, y.title)) for result in searchresults: if ((??.meta_type == 'File') or (??.meta_type == 'zIndexFileItem')): if (??.getContentType == "application/pdf"): PDF Specific Code Here
_______________________________________________ Zope maillist - Zope@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 )
-- Hacker is to software engineer as Climbing Mt. Everest is to building a Denny's there.
I'm pulling my hair out here. I'm sure the answer is simple.
How can I get to properties of an object from its ZCatalog entry?
I'm iterating through results, and want to do something special if the result is a record for a PDF file. I know how to check the file to see if its a PDF, but ZCatalog does not keep track of all the file contents. I know there is a way to resolve the record ID into the actual object, but I forget how and cannot find a reference to it.
Maybe this will help: http://www.zope.org/Members/jccooper/zcatalogAndPT I'm sure you can translate from ZPT to Python. --jcc
tal:define="url python: result.getpath(result.data_record_id_)" and results are defined as <div tal:define="results here/SiteCatalog"> somewhere above that .. On Thu, 2003-03-06 at 16:30, Edward Pollard wrote:
I'm pulling my hair out here. I'm sure the answer is simple.
How can I get to properties of an object from its ZCatalog entry?
I'm iterating through results, and want to do something special if the result is a record for a PDF file. I know how to check the file to see if its a PDF, but ZCatalog does not keep track of all the file contents. I know there is a way to resolve the record ID into the actual object, but I forget how and cannot find a reference to it.
Thanks,
Edward
---- For clarity, here is some of my code. I am looking for what to use instead of ?? zIndex_Catalog is my Catalog. zIndexFileItem is my CatalogAware wrapper ZClass for File.
searchresults = list(context.zIndex_Catalog.searchResults(blah blah search params blah blah)) searchresults.sort( lambda x, y: cmp(x.title, y.title)) for result in searchresults: if ((??.meta_type == 'File') or (??.meta_type == 'zIndexFileItem')): if (??.getContentType == "application/pdf"): PDF Specific Code Here
_______________________________________________ Zope maillist - Zope@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 ) -- Edward Muller
Interlix - President Web Hosting - PC Service & Support Custom Programming - Network Service & Support Phone: 417-862-0573 Cell: 417-844-2435 Fax: 417-862-0572 http://www.interlix.com
Honestly, I don't remember why. Looking back at when I did the code ... It was probably because I didn't know about .getPath() There are times when, while I don't think they are the end all - be all of docs, I really want a javadoc equivalent for python ... And a complete set of them for the classes in zope. On Mon, 2003-03-10 at 08:16, Chris Withers wrote:
Edward Muller wrote:
tal:define="url python: result.getpath(result.data_record_id_)"
why not just use result.getPath()? (you may actually want result.getURL()...)
cheers,
Chris
_______________________________________________ Zope maillist - Zope@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 ) -- Edward Muller
Interlix - President Web Hosting - PC Service & Support Custom Programming - Network Service & Support Phone: 417-862-0573 Cell: 417-844-2435 Fax: 417-862-0572 http://www.interlix.com
Edward Muller wrote:
Honestly, I don't remember why. Looking back at when I did the code ... It was probably because I didn't know about .getPath()
There are times when, while I don't think they are the end all - be all of docs, I really want a javadoc equivalent for python ... And a complete set of them for the classes in zope.
Such tools exist, check the mailing list archives... cheers, Chris
On Thursday 06 March 2003 23:30, Edward Pollard wrote:
I'm pulling my hair out here. I'm sure the answer is simple.
How can I get to properties of an object from its ZCatalog entry?
I'm iterating through results, and want to do something special if the result is a record for a PDF file. I know how to check the file to see if its a PDF, but ZCatalog does not keep track of all the file contents. I know there is a way to resolve the record ID into the actual object, but I forget how and cannot find a reference to it.
---- For clarity, here is some of my code. I am looking for what to use instead of ?? zIndex_Catalog is my Catalog. zIndexFileItem is my CatalogAware wrapper ZClass for File.
searchresults = list(context.zIndex_Catalog.searchResults(blah blah search params blah blah)) searchresults.sort( lambda x, y: cmp(x.title, y.title)) for result in searchresults: if ((??.meta_type == 'File') or (??.meta_type == 'zIndexFileItem')): if (??.getContentType == "application/pdf"): PDF Specific Code Here
The method to use on the ZCatalog result record is "getObject()". So you may have an improved version of your code like this : query = {} query['param1'] = value1 query['param2'] = value2 query['sort_on'] = 'title' for result in context.zIndex_Catalog.searchResults (query): if result.meta_type in ['File','zIndexFileItem']: object = result.getObject() if object.getContentType == 'application/pdf': <PDF specific code> This should work (as long as 'meta_type' is in your ZCatalog metadatas). Thierry
participants (6)
-
Chris Withers -
Edward Muller -
Edward Pollard -
J Cameron Cooper -
Shannon -jj Behrens -
Thierry FLORAC