How does one access a ZClass property from a ZClass method?
I have a ZClass with a property sheet that contains two properties. I then created a method for the ZClass that tried to access the properties. For example: I created a property sheet that contained a float property named "high". I then created a DTML memo in the methods section of the ZClass. But when I put something like <dtml-var high> in the method, I get a KeyError saying that high doesn't exist? Obviously, I'm not understanding something somewhere. What am I doing wrong? ---------- Michael Grinder grinder@cs.montana.edu "Well, I've wrestled with reality for 35 years, doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd in "Harvey"
On Mon, Apr 24, 2000 at 05:51:20PM -0600, Michael Grinder wrote:
I have a ZClass with a property sheet that contains two properties. I then created a method for the ZClass that tried to access the properties. For example: I created a property sheet that contained a float property named "high". I then created a DTML memo in the methods section of the ZClass. But when I put something like <dtml-var high> in the method, I get a KeyError saying that high doesn't exist? Obviously, I'm not understanding something somewhere. What am I doing wrong?
How are you calling your ZClass? If it is from a <dtml-var> statement, you need to specify the namespace explicitly for some odd reason: <dtml-var "zclass.method(zclass, _)"> Which reminds me, will ZClasses be auto-renderable inside tags in the future? It seems silly that you can have an index_html method that is rendered from a URL, but have to specify stuff as above to use it from other DTML Methods/Documents. Is there a better way that I'm not aware of? Cheers, jdrowell -- John Douglas Rowell Home of jdfetch 0.4.0, jdresolve 0.5.2, me@jdrowell.com jdrinfo 0.2, jdtracker 0.11 and http://www.jdrowell.com jdwhatsnew 0.21 Member of the AppWatch staff - http://appwatch.com - staff@appwatch.com
"John D. Rowell" wrote:
On Mon, Apr 24, 2000 at 05:51:20PM -0600, Michael Grinder wrote:
I have a ZClass with a property sheet that contains two properties. I then created a method for the ZClass that tried to access the properties. For example: I created a property sheet that contained a float property named "high". I then created a DTML memo in the methods section of the ZClass. But when I put something like <dtml-var high> in the method, I get a KeyError saying that high doesn't exist? Obviously, I'm not understanding something somewhere. What am I doing wrong?
How are you calling your ZClass? If it is from a <dtml-var> statement, you need to specify the namespace explicitly for some odd reason:
<dtml-var "zclass.method(zclass, _)">
Which reminds me, will ZClasses be auto-renderable inside tags in the future? It seems silly that you can have an index_html method that is rendered from a URL, but have to specify stuff as above to use it from other DTML Methods/Documents. Is there a better way that I'm not aware of?
Cheers, jdrowell
Ok two questions, mike, from your desciption it seems like your trying to view the method in the management interface of the Control Panel. I'm not up and the exact details but here goes. When you create a ZClass in the Products folder, you're basically creating a class definition. but to actually watch your class in action (ie view, call methods, etc) you need to instantiate/create an object based on that definition/type in another folder besides the control panel by selecting your ZClass from the add item menu. if you're still having problems can you send a traceback and the show how you call the method. jd, about renderable Zclasses, try inheriting from the Renderable Product which basically implements python hooks for __call__, with that and a render method (i normally define it as index_html) you can render your ZClasses directly in dtml: <dtml-var YourZClass> or <dtml-in "ObjectItems(['YourZClass'])"> <dtml-var sequence-item> </dtml-in> Kapil www.sin.wm.edu
"John D. Rowell" wrote:
How are you calling your ZClass? If it is from a <dtml-var> statement, you need to specify the namespace explicitly for some odd reason:
<dtml-var "zclass.method(zclass, _)">
That did it! Thanks, John. Kapil wrote:
mike, from your desciption it seems like your trying to view the method in the management interface of the Control Panel.
No. I was calling it from a DTML Document in a dtml-var like above. Sorry for not giving quite enough detail. Michael ---------- Michael Grinder grinder@cs.montana.edu "Well, I've wrestled with reality for 35 years, doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd in "Harvey"
On Mon, Apr 24, 2000 at 08:18:00PM -0400, Kapil Thangavelu wrote:
jd, about renderable Zclasses, try inheriting from the Renderable Product which basically implements python hooks for __call__, with that and a render method (i normally define it as index_html) you can render your ZClasses directly in dtml:
<dtml-var YourZClass>
or
<dtml-in "ObjectItems(['YourZClass'])"> <dtml-var sequence-item> </dtml-in>
Thanks Kapil, I'll try that. BTW, is there any way to modify the class to add another base class without starting from scratch? Also, I'm having problems with acquisition that may be related to forcing the client when rendering ZClasses: - ZBox is a ZClass that renders fancy boxes - standard_html_header in the root folder uses ZBox (using the <dtml-var "zclass.method(zclass, _)"> syntax) - ZLeaf is a folder-aware DTML Document that creates links to other documents in that folder as part of a toolbar. It uses the standard_html_header in that folder, which calls the root standard_html_header (thru PARENT) When I render my ZLeaf, I get a ErrorValue: __call__ error in the ZBox class (instance). All of the index_html is rendered ok, only the ZBox bombs. The, even weirder: - index_html on root (calling the ZBox) - folder f (no index_html) Trying to access the URL "http://server/f" gives exactly the same error. This looks like if I acquire a DTML Document that contains a ZClass, it will fail, while calling that document directly succeeds. The dump: -------- Error Type: AttributeError Error Value: __call__ Traceback (innermost last): File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 214, in publish_module File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 179, in publish File /home/jdrowell/Zope-2.1.6-src/lib/python/Zope/__init__.py, line 202, in zpublisher_exception_hook (Object: ElementWithAttributes) File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 165, in publish File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 102, in call_object (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/OFS/DTMLDocument.py, line 166, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_Util.py, line 335, in eval (Object: box_search.index_html(box_search, _)) (Info: box_search) File <string>, line 0, in ? File /home/jdrowell/Zope-2.1.6-src/lib/python/OFS/DTMLMethod.py, line 150, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: index_html) AttributeError: (see above) ------ I'm using workarounds to handle this problem, but would much rather use a straight approach. Any hints? Thanks, jdrowell -- John Douglas Rowell Home of jdfetch 0.4.0, jdresolve 0.5.2, me@jdrowell.com jdrinfo 0.2, jdtracker 0.11 and http://www.jdrowell.com jdwhatsnew 0.21 Member of the AppWatch staff - http://appwatch.com - staff@appwatch.com
"John D. Rowell" wrote: <snip>
Thanks Kapil, I'll try that. BTW, is there any way to modify the class to add another base class without starting from scratch?
i feel bad for posting this, and i can't even say if it will work, and it might hose your ZODB, and curdle your milk, and lots of other unspeakable nasties, in other words use at your own risk and beware. http://www.zope.org/Members/AlexR/ChangingBaseClasses
Also, I'm having problems with acquisition that may be related to forcing the client when rendering ZClasses:
- ZBox is a ZClass that renders fancy boxes - standard_html_header in the root folder uses ZBox (using the <dtml-var "zclass.method(zclass, _)"> syntax) - ZLeaf is a folder-aware DTML Document that creates links to other documents in that folder as part of a toolbar. It uses the standard_html_header in that folder, which calls the root standard_html_header (thru PARENT)
yikes, nested/looping acquisition contexts are a mess. folder-aware document?
When I render my ZLeaf, I get a ErrorValue: __call__ error in the ZBox class (instance). All of the index_html is rendered ok, only the ZBox bombs. The, even weirder:
- index_html on root (calling the ZBox) - folder f (no index_html)
Trying to access the URL "http://server/f" gives exactly the same error. This looks like if I acquire a DTML Document that contains a ZClass, it will fail, while calling that document directly succeeds.
Dtml Document containing a ZClass??.. maybe the other way around.
The dump:
--------
Error Type: AttributeError Error Value: __call__
Traceback (innermost last): File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 214, in publish_module File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 179, in publish File /home/jdrowell/Zope-2.1.6-src/lib/python/Zope/__init__.py, line 202, in zpublisher_exception_hook (Object: ElementWithAttributes) File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 165, in publish File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/ZPublisher/Publish.py, line 102, in call_object (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/OFS/DTMLDocument.py, line 166, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_Util.py, line 335, in eval (Object: box_search.index_html(box_search, _)) (Info: box_search) File <string>, line 0, in ? File /home/jdrowell/Zope-2.1.6-src/lib/python/OFS/DTMLMethod.py, line 150, in __call__ (Object: index_html) File /home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: index_html) AttributeError: (see above)
------
I'm using workarounds to handle this problem, but would much rather use a straight approach. Any hints?
Thanks, jdrowell
hmmm... i'm not sure if i want to try and debug this, mainly because i would have done things a bit differently and i don't have the code to play with. what i would try: first make Zleaf a method, this is the clasic def. of a method, since its acting on its container. if its just looking for documents to link it could be as simple as. <table><tr> <dtml-in "objectItems(['DTML Document'])"> <dtml-with sequence-item> <td><a href="<dtml-var absolute_url>"><dtml-var title_or_id></a></td> </dtml-with> </dtml-in> <tr></table> you can call this method somewhere in your root index_html wherever you want the toolbar like this <dtml-var "FolderContainingMethodAccesibleFrom Root.ZLeaf(_.None, _)"> if you feel like debuggin your current situation this line looks suspicious
/home/jdrowell/Zope-2.1.6-src/lib/python/DocumentTemplate/DT_Util.py, line 335, in eval (Object: box_search.index_html(box_search, _)) (Info: box_search) at this point i think the error has already occured. although, i don't think you need to pass a client folder to index_html since your giving it one already by using the box_search. notation. hmm.. maybe try and take out the nested standard_html_headers. i'm out of ideas.
regarding zboxes and jdfetch: you might want to check out RSSChannel, instead of having an external perl script, plus it gives you Catalog indexin of the headlines. www.moreover.com , and www.headlinewatch.com have thousands of RSS/XML feeds/ i'll be working on something similiar for a community portal in the near future. I hope that helps, Kapil www.sin.wm.edu
Doh... i tried testing this (and some variations) and it doesn't seem to work outside of the root folder. anyone have any ideas?
first make Zleaf a method, this is the clasic def. of a method, since its acting on its container. if its just looking for documents to link it could be as simple as. <table><tr> <dtml-in "objectItems(['DTML Document'])"> <dtml-with sequence-item> <td><a href="<dtml-var absolute_url>"><dtml-var title_or_id></a></td> </dtml-with> </dtml-in> <tr></table>
you can call this method somewhere in your root index_html wherever you want the toolbar like this <dtml-var "FolderContainingMethodAccesibleFrom Root.ZLeaf(_.None, _)">
i tried it putting the method in the root folder and as above, and with an equivalent different method, and directly in standard_header but if i switch folders i always get the same error. traceback below. incidentally i found that a checking for DTML Method in the root folder won't show any of the standard_ stuff. any help appreciated. Kapil www.sin.wm.edu TypeError Sorry, a Zope error occurred. Traceback (innermost last): File /home/smog/asti/Zope/lib/python/ZPublisher/Publish.py, line 214, in publish_module File /home/smog/asti/Zope/lib/python/ZPublisher/Publish.py, line 179, in publish File /home/smog/asti/Zope/lib/python/Zope/__init__.py, line 202, in zpublisher_exception_hook (Object: ElementWithAttributes) File /home/smog/asti/Zope/lib/python/ZPublisher/Publish.py, line 165, in publish File /home/smog/asti/Zope/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: index_html) File /home/smog/asti/Zope/lib/python/ZPublisher/Publish.py, line 102, in call_object (Object: index_html) File /home/smog/asti/Zope/lib/python/OFS/DTMLMethod.py, line 150, in __call__ (Object: index_html) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: index_html) File /home/smog/asti/Zope/lib/python/OFS/DTMLMethod.py, line 146, in __call__ (Object: standard_html_header) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: standard_html_header) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_In.py, line 691, in renderwob (Object: objectItems(['DTML Method'])) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_With.py, line 132, in render (Object: sequence-item) File /home/smog/asti/Zope/lib/python/OFS/DTMLMethod.py, line 146, in __call__ (Object: searchEmail) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: searchEmail) File /home/smog/asti/Zope/lib/python/OFS/DTMLMethod.py, line 146, in __call__ (Object: standard_html_header) File /home/smog/asti/Zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: standard_html_header) TypeError: too many arguments; expected 2, got 3
On Tue, Apr 25, 2000 at 12:37:55AM -0400, Kapil Thangavelu wrote:
i feel bad for posting this, and i can't even say if it will work, and it might hose your ZODB, and curdle your milk, and lots of other unspeakable nasties, in other words use at your own risk and beware.
Will try it out, thanks :)
Also, I'm having problems with acquisition that may be related to forcing the client when rendering ZClasses:
- ZBox is a ZClass that renders fancy boxes - standard_html_header in the root folder uses ZBox (using the <dtml-var "zclass.method(zclass, _)"> syntax) - ZLeaf is a folder-aware DTML Document that creates links to other documents in that folder as part of a toolbar. It uses the standard_html_header in that folder, which calls the root standard_html_header (thru PARENT)
yikes, nested/looping acquisition contexts are a mess. folder-aware document?
Uhmm, I wouldn't say so. The idea is to keep site globals (headers, footers, boxes, etc) in DTML Methods in the root folder. These are acquired by the subfolders, which optimally only contain ZClasses (I tend to change my mind about design and functionality, and want maximum flexibility). The only thing I'm really trying to acomplish here is to acquire a DTML Method that calls ZClasses, and use that inside another ZClass. This seems to fail most (all) of the time. The fact that an acquisition path is not trivial should not break the model, since things tend to get complicated when you build a large site anyway. The "folder-aware document" is the name I give to my documents that have knowledge of their parent folder and its items, and uses that to generate content inside itself (through lookup or iteration, not direct reference).
Trying to access the URL "http://server/f" gives exactly the same error. This looks like if I acquire a DTML Document that contains a ZClass, it will fail, while calling that document directly succeeds.
Dtml Document containing a ZClass??.. maybe the other way around.
It actually calls a ZClass, excuse my bad use of the term "contain". Then call is contained inside the document ;)
The dump:
--------
Error Type: AttributeError Error Value: __call__
first make Zleaf a method, this is the clasic def. of a method, since its acting on its container. if its just looking for documents to link it could be as simple as. <table><tr> <dtml-in "objectItems(['DTML Document'])"> <dtml-with sequence-item> <td><a href="<dtml-var absolute_url>"><dtml-var title_or_id></a></td> </dtml-with> </dtml-in> <tr></table>
I actually have this working in a similar way (the ZLeaf class is on hold until I have a better grasp of the acquisition problem) , but my i objective here is to take the opportunity of this site redesign to structure it in the best way possible and release some Zope Products along the way. For this to be successful, everything has to work as planned, and not as a workaround for what didn't work. I already have a finished product (PathEater, name stolen from discussions on this list ;)) that solves all of my __bobo_traverse__ problems in a neat way, which I just started testing yesterday and should be releasing later this week if all goes well. It contains a one-line patch to ZPublisher/BaseRequest.py, and I'd like to determine if my other areas of trouble are Zope bugs or just misunderstandings on my part before I submit additional patches.
regarding zboxes and jdfetch: you might want to check out RSSChannel, instead of having an external perl script, plus it gives you Catalog indexin of the headlines.
Uhmm, the ZBox I'm talking about is something unreleased, maybe there is another product by that name out there already. jdfetch is a really old solution from the Zope 1.x days that I haven't had time to update recently (it does work though ;)). I'll try RSSChannel when I revamp jdrowell.com.
www.moreover.com , and www.headlinewatch.com have thousands of RSS/XML feeds/
Yes, XML is the way to do it right. O'Reilly is making some significant advances in wrapping something around these feeds with Meerkat (http://oreillynet.com/meerkcat). They also have an ongoing discussion about new RSS standards and use many of the moreover.com feeds. You should get in touch with them about new standards in that area as they already have some experience with this volume of feeds. Cheers, jdrowell -- John Douglas Rowell Home of jdfetch 0.4.0, jdresolve 0.5.2, me@jdrowell.com jdrinfo 0.2, jdtracker 0.11 and http://www.jdrowell.com jdwhatsnew 0.21 Member of the AppWatch staff - http://appwatch.com - staff@appwatch.com
----- Original Message ----- From: "John D. Rowell" <jdrowell@appwatch.com> To: <zope@zope.org> Sent: Monday, April 24, 2000 8:06 PM Subject: Re: [Zope] How does one access a ZClass property from a ZClass method?
<dtml-var "zclass.method(zclass, _)">
Which reminds me, will ZClasses be auto-renderable inside tags in the future? It seems silly that you can have an index_html method that is rendered from a URL, but have to specify stuff as above to use it from other DTML Methods/Documents. Is there a better way that I'm not aware of?
There has been talk of trying to create a mechanism to do this, but there's a very good reason for the way it works now. When you access the method via a URL, Zope automatically passes in the requisite namespace, REQUEST, etc. If you do, <dtml-var method> this is equivalent to <dtml-var name=method>. In this context, Zope passes the proper parameters in automatically as well. <dtml-var "method(_.None, _)"> is equivalent to <dtml-var expr="method(_.None, _)"> which is actually a Python expression. And *that's* why you need to pass in those parameters... because Zope is not doing the calling... python is. And python does not automatically pass the namespace in as a parameter. There has been talk about trying to change this in the past, but no one had concrete said they were going to try to implement something. Personally, I don't think it's so bothersome when you get used to it. In fact, I've even used the client parameter (the first argument) for a useful purpose a couple of times. Kevin
----- Original Message ----- From: "Michael Grinder" <grinder@cs.montana.edu> To: "Zope Mailing List" <zope@zope.org> Sent: Monday, April 24, 2000 7:51 PM Subject: [Zope] How does one access a ZClass property from a ZClass method?
I have a ZClass with a property sheet that contains two properties. I then created a method for the ZClass that tried to access the properties. For example: I created a property sheet that contained a float property named "high". I then created a DTML memo in the methods section of the ZClass. But when I put something like <dtml-var high> in the method, I get a KeyError saying that high doesn't exist? Obviously, I'm not understanding something somewhere. What am I doing wrong?
Is this a DTML Method or a DTML Document? If it's a DTML Method, what you're describing sounds good to me... Kevin
participants (4)
-
John D. Rowell -
Kapil Thangavelu -
Kevin Dangoor -
Michael Grinder