Hello, I've created a set of custom ZClasses, and can't associate them with a cache manager. I see there isn't a baseclass available in the ZMI that corresponds to the 'Cacheable' class in 'cache.py' in the OFS directory of Zope. I suppose I could subclass another class that is cacheable, like DTML Document, but will that just cache the DTML Document portions of my class? I just want my ZClass to be cacheable, so ideas are welcome. much thanks, bart
Bart Hubbard wrote at 2003-8-26 15:13 -0500:
I've created a set of custom ZClasses, and can't associate them with a cache manager. I see there isn't a baseclass available in the ZMI that corresponds to the 'Cacheable' class in 'cache.py' in the OFS directory of Zope. I suppose I could subclass another class that is cacheable, like DTML Document, but will that just cache the DTML Document portions of my class?
I just want my ZClass to be cacheable, so ideas are welcome.
Cachable classes must implement the ZCachable protocol. This essentially means that they themselves must ask the cache manager, whether it already has something cached for them and if not, register the computed value with the cache manager. This is built in into many basic object classes. But, as you easily understand, it is impossible for ZClasses. You may build wrappers around your ZClass methods (!) implementing the ZCachable protocol. Dieter
Hello again, I have a python script that returns an object. I then call that script from DTML, and then call a method on that object, like this: <dtml-with expr="getArticleByCategory(findCat='cancer')"> <dtml-var view> </dtml-with> I'd like to have my script call the method, and return the resulting HTML, instead, though. My script is the following: import random zcat = context.content.Catalog results = zcat(category=findCat) itemId = random.choice(results).id item = context.content.HealthFeatures[itemId] return item; When I try to have the script call 'view()', I get a KeyError telling me I'm referencing a non-existent object or variable "headline" (which happens to be an attribute on that content object). So it looks like I'm having a namespace problem, which my DTML snippet at the top resolves. So how do I accomplish in a single python script what I'm accomplishing above using DTML and python? Much thanks, bart
see the zope book, advanced scripting chapter http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx search for "Calling DTML from Scripts" Bart Hubbard wrote:
Hello again,
I have a python script that returns an object. I then call that script from DTML, and then call a method on that object, like this: <dtml-with expr="getArticleByCategory(findCat='cancer')"> <dtml-var view> </dtml-with>
I'd like to have my script call the method, and return the resulting HTML, instead, though. My script is the following:
import random
zcat = context.content.Catalog results = zcat(category=findCat) itemId = random.choice(results).id item = context.content.HealthFeatures[itemId] return item;
When I try to have the script call 'view()', I get a KeyError telling me I'm referencing a non-existent object or variable "headline" (which happens to be an attribute on that content object). So it looks like I'm having a namespace problem, which my DTML snippet at the top resolves.
So how do I accomplish in a single python script what I'm accomplishing above using DTML and python?
Much thanks, bart
_______________________________________________ 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 )
Whoops! Good point. I had edited my question many times w/o changing the title. My real situation is a little more complex than the question I'd posed. What I'm really doing is trying to do in ZPT what I was doing in a DTML doc. I also wanted to clean up my design by moving the logic to my script. My script finds an object fine, but I couldn't get it to execute a method properly that the object contained. Thanks to Peter Sabaini's hint, I have it working now. I now have the script explicitly setting the context before attempting to execute the method. The updated test script now works great, and is (no error handling in there, yet): import random # Get content catalog and search for an object using the args # and the current date/time zcat = context.content.Catalog results = zcat(category=findCat, meta_type=findType, publishDateRange=DateTime()) # Pick one content object at random item = random.choice(results).getObject() # Prepare to call the view method on the content object dtml_method = item.view REQUEST = context.REQUEST # Call the method in the context of that item and return the results retVal = dtml_method(client=item, REQUEST=REQUEST) return retVal Next I plan to allow various 'views' to be requested from the script based on an argument, as well. Then I'll have a good script to use in my ZPTs to request the various types of content I have indexed. Thanks for the help, bart
-----Original Message----- From: Chris Withers [mailto:chrisw@nipltd.com] Sent: Wednesday, September 03, 2003 8:15 AM To: Bart Hubbard Cc: zope@zope.org Subject: Re: [Zope] Calling Python script from ZPT [...]
Why the ZPT title?
If you were using ZPT you probably wouldn't have the problem ;-) [...]
Bart Hubbard wrote:
Whoops! Good point. I had edited my question many times w/o changing the title. My real situation is a little more complex than the question I'd posed. What I'm really doing is trying to do in ZPT what I was doing in a DTML doc. I also wanted to clean up my design by moving the logic to my script.
Well, post the bits of ZPT and Python Script that aren't working and I can help ;-)
# Call the method in the context of that item and return the results retVal = dtml_method(client=item, REQUEST=REQUEST)
If you could make that not DTML, your life would get even easier, since to call a page template, you could replace: # Prepare to call the view method on the content object dtml_method = item.view REQUEST = context.REQUEST # Call the method in the context of that item and return the results retVal = dtml_method(client=item, REQUEST=REQUEST) return retVal with: return item.view() ...since ZPT has very well defined and consistent calling semantics, whereas DTML doesn't ;-) cheers, Chris
participants (4)
-
Bart Hubbard -
Chris Withers -
Dieter Maurer -
Peter Sabaini