Retrieve calling object from python script
I've written a cache parameter script in Python, which is designed to be called without arguments from a dtml page, zpt or as a precondition to a File or Image object. It needs to get a handle on the item which called it (I'll call that handle 'object'), to retrieve optional script parameters stored as properties of the calling object. This allows per instance configuration of ZPTs, and suchlike. Here's the start of the script: #start request = context.REQUEST object = request.PUBLISHED response = request.RESPONSE # DEBUG: look at PUBLISHED response.setHeader('Published-Object', repr(object)) try: object.getId() except: object = context # function shortcuts hasProperty = object.propertysheets.hasProperty getProperty = object.propertysheets.getProperty #... #end So, for ZPTs I call the script with 'here/cache', and I get: Published-Object: <ZopePageTemplate at index_html> ...'context' alone gives a handle on the item's container (e.g. Folder). This is fine. Now, for Files and Images, a set the Precondition to 'cache' and I get: Published-Object: <bound method File.index_html of <File instance at a045230>> ...the .getId() fails, and it uses context, which works (e.g. I can access the File's propertysheets), but isn't beautiful. However, this fails for ZCGI objects. I get: Published-Object: <bound method ZCGIFolder.index_html of <ZCGIFolder at /Base/ht-bin>> ...but 'context' refers to the <CMFSite instance>, /Base, not to the ZCGIFolder, /Base/ht-bin. So the question is this: what's the proper way to identify the object whose method has been bound to REQUEST.PUBLISHED, or if that's the wrong route, to simply, reliably identify the caller of a python script which can be called from a range of different object types? Thanks, - Robin -- Robin Breathe, Computer Services, Oxford Brookes University, Oxford, UK rbreathe@brookes.ac.uk Tel: +44 1865 483323 Fax: +44 1865 483073
participants (1)
-
Robin Breathe