call an object from within a product
Hi there, my question is probably quite stupid, but I can't find the answer anywhere: how to call an object from a product? I would like to obtain exactly the same result as if the object was called through the web or with dtml-var. I wrote something like: #get the object object = self.unrestrictedTraverse(url) try: #Call the object as a DTML method htmlsource = localObject.__call__(object, REQUEST) except: #Call the object as a folder htmlsource = localObject.index_html.__call__(object, REQUEST) This works for folders and DTML Methods, but not for images... I would like to let ZPublisher do the work for me!
Benjamin Buffereau writes:
How to call an object from a product? I would like to obtain exactly the same result as if the object was called through the web or with dtml-var. Your question in not stupid at all and it is not at all simple. In fact, it is impossible:
ZPublisher and "dtml-var" call objects in very different ways (although you may not always see the differences). You may have a look at my "Dispatcher" product at <http://www.dieter.handshake.de/pyprojects/zope> It tries to do something similar than you want. Due to the problems mentioned, it is not perfect and I am not completely satisfied with it. Dieter
Thank you Dieter, I had a look at your Dispatcher product, but I obviously lack knowledge of the internal zope machinery to understand what you're exactly doing. I tried to copy/paste your "mapply infrastructure" in an External Method, but I get a SystemError: "Failed to import class _missing_name from module __main__". I didn't think that just get the value of an object would be such a mess. I think I'll try this ugly solution: object_value = urllib.urlopen("localhost:8080"+object_path).read() Benjamin. Dieter Maurer wrote:
Your question in not stupid at all and it is not at all simple. In fact, it is impossible:
ZPublisher and "dtml-var" call objects in very different ways (although you may not always see the differences).
You may have a look at my "Dispatcher" product at
<http://www.dieter.handshake.de/pyprojects/zope>
It tries to do something similar than you want. Due to the problems mentioned, it is not perfect and I am not completely satisfied with it.
Dieter
Benjamin Buffereau writes:
I had a look at your Dispatcher product, but I obviously lack knowledge of the internal zope machinery to understand what you're exactly doing. I tried to copy/paste your "mapply infrastructure" in an External Method, but I get a SystemError: "Failed to import class _missing_name from module __main__".
I didn't think that just get the value of an object would be such a mess. I think I'll try this ugly solution:
object_value = urllib.urlopen("localhost:8080"+object_path).read() If you just want to access the object, then, you can use "restrictedTraverse". The calling magic is the difficult part.
Dieter
Dieter Maurer wrote:
If you just want to access the object, then, you can use "restrictedTraverse". The calling magic is the difficult part.
No, I really would like to call the object from my product, using Zope wonderful calling machinery. And I really don't understand why there isn't an interface to do that. It seems to me that ZPublisher offers two services: URL traversal, and calling magic. The first one has a good and easy interface with restricted_traverse and unrestricted_traverse. It's a pity that the second service is unaccessible to an average product developper like me... I would be glad if there is a guru somewhere that has some time to spend writing a product to do that ;-) Benjamin.
Benjamin Buffereau writes:
Dieter Maurer wrote:
If you just want to access the object, then, you can use "restrictedTraverse". The calling magic is the difficult part.
No, I really would like to call the object from my product, using Zope wonderful calling machinery. When you are in DTML (or have a DTML namespace) and you have an object "o", then you can use "_.render(o)". This usually does what you want.
Dieter
participants (2)
-
Benjamin Buffereau -
Dieter Maurer