the joy of hacking ZPublisher
In my Zope 2.7 Product, I'm trying to implement a special folder, which intercepts the publishing call to any subobject and wraps the entire call in another. A concrete example: where the default action would be to traverse /MyProduct/SpecialFolder/something, and publish the attr 'something' from SpecialFolder, I want this to happen instead: doSomethingBeforeCallingTheRequestedObj() try: return mapply( something, blahblah...) finally: doSomethingAfterCallingTheRequestedObj() Why? I need to do stuff to the REQUEST before the object is called (this part wasn't difficult), and then do something *after* it's called - no matter what the results were. But only for publishables that live in or beneath the Special Folder. In fact I have something working, but one big problem - it breaks management screens in a bad way. The implementation is pasted below. Is there some much simpler way to accomplish this behavior? And am I short-circuiting security machinery in some dangerous way? class Wrapper(Implicit): """voodoo""" id = meta_type = title = "Wrapper" def __init__(self, publishable): self.pub = publishable def index_html(self): """ render the results to the client """ REQUEST = self.REQUEST print self.__class__.__name__, 'calling', self.pub try: return mapply(self.pub, REQUEST.args, REQUEST, call_object,1, missing_name, dont_publish_class, REQUEST, bind=1) finally: print self.__class__.__name__, 'done' print '' print '' __call__ = index_html Globals.InitializeClass(Wrapper) class SpecialFolder(Folder): def __bobo_traverse__ (self,REQUEST,key): print '__bobo_traverse__', REQUEST.URL, key stack = REQUEST['TraversalRequestNameStack'] target = getattr(self,key) if stack: return target return Wrapper(target).__of__(self)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jim Abramson wrote:
In my Zope 2.7 Product, I'm trying to implement a special folder, which intercepts the publishing call to any subobject and wraps the entire call in another.
A concrete example: where the default action would be to traverse /MyProduct/SpecialFolder/something, and publish the attr 'something' from SpecialFolder, I want this to happen instead:
doSomethingBeforeCallingTheRequestedObj() try: return mapply( something, blahblah...) finally: doSomethingAfterCallingTheRequestedObj()
Why? I need to do stuff to the REQUEST before the object is called (this part wasn't difficult), and then do something *after* it's called - no matter what the results were. But only for publishables that live in or beneath the Special Folder.
Sounds like you want what AccessRules provide, which is a way to provide a configurable hook into the publishing traversal process. The following thread explains the rationale for that hook, from before it was included in Zope proper: http://mail.zope.org/pipermail/zope-dev/1999-December/002667.html
In fact I have something working, but one big problem - it breaks management screens in a bad way. The implementation is pasted below. Is there some much simpler way to accomplish this behavior? And am I short-circuiting security machinery in some dangerous way?
Tres. - -- =================================================================== Tres Seaver tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCi5L0+gerLs4ltQ4RAvexAJ9jh3QN7Nk5HN+zjdjQzUeshX4NAwCfQgEF fhJpTReSx95BQ4aR3KG69IM= =LsRY -----END PGP SIGNATURE-----
participants (2)
-
Jim Abramson -
Tres Seaver