Ok, I've gotten pretty far with Zope this time. But (of course), I've got a bunch of questions. Starting with... 1) What is the algorithm for determining which method to call? The DTML documentation says "attributes, including inherited and acquired attributes, of the client passed in the call to the document template are searched" But in what order? There can be an index_html in the class, in a parent class, or somewhere up the acquisition tree. Which takes precedence? Does the product that a ZClass have anything to do with the search? What about Z-Super-Classes? Inquiring minds want to know. 1a) Why can't I have a method in a ZClass, but then override it in the instance? I.E. (Gaak, it has been a while since I've had to even think about C++) virtual methods? (Or have I got that wrong). 2) It seems that the examples require the user to generate forms by hand, which seems unnecessary. For example, (after a protracted struggle with the underlying python code) I wrote a method that would create an html table for any query, ripping the column names and data out of the result object. 2.1) Shouldn't this be a standard part of Zope? 2.2) If so, do you want this code? 2.2) Likewise for property edit forms. I did find some DTML that would do this, but shouldn't this be standard. 3) Anyone want to help me whip snmpy into shape and create soem nice Zope classes for accessing SNMP variables and tables in routers and such? Enough for now... -- cary cobrien@radix.net
On Tue, 7 Mar 2000, Cary O'Brien wrote:
Ok, I've gotten pretty far with Zope this time. But (of course), I've got a bunch of questions. Starting with...
1) What is the algorithm for determining which method to call? The DTML documentation says
"attributes, including inherited and acquired attributes, of the client passed in the call to the document template are searched"
But in what order? There can be an index_html in the class, in a parent class, or somewhere up the acquisition tree. Which takes precedence? Does the product that a ZClass have anything to do with the search? What about Z-Super-Classes? Inquiring minds want to know.
I would have to research this to give a precise answer. Basically, it all depends on the current contents of the namespace stack. Generally, this will search REQUEST first. Next, we look to the object containing the method being rendered. Then, the object containing that object, etc. Whenever a ZClass is queried for an attribute and doesn't have it, it looks to its parent(s).
1a) Why can't I have a method in a ZClass, but then override it in the instance? I.E. (Gaak, it has been a while since I've had to even think about C++) virtual methods? (Or have I got that wrong).
I made this mistake when first working with ZClasses, too. If you think about it a little, you'll realize that, virtual or not, you cannot customize an OBJECT in C++, only a CLASS. i.e.: --- class A { public: int x; public: A() { x = 0; } }; class B : public A { public: int y; public: B() { y = 0; } }; A* objectA = new A(); B* objectB = new B(); objectA->x = 1; // Valid objectB->y = 2; // Valid objectA->y = 2; // Invalid, because class A has no such attribute. objectB->z = 3; // Invalid, because class B has no such attribute. --- If you want to customize an object (instance), you have to extend its class, first. In Python, this is not (really) true. Any old object is a dictionary, so yuo can add attributes to it on the fly. Thus, the question, how can we do this with ZClasses? I wrote a base class that overloads ObjectManager's _checkId method to allow instances of a ZClass to be customized. It looks like this: --- from OFS.ObjectManager import bad_id class Overridable: def _checkId(self, id, allow_dup = 0): if not id: raise 'Bad Request', 'No id was specified' if bad_id(id) != -1: raise 'Bad Request', ( 'The id %s contains characters illegal in URLs' % id) if id[0] == '_': raise 'Bad Request', ( 'The id %s is invalid - it begins with an underscore' % id) if not allow_dup: if hasattr(self, 'aq_base'): self = self.aq_base if self.__dict__.has_key(id): raise 'Bad Request', ( 'The id %s is invalid - it is already in use' % id) --- This is not foolproof (it allows you to override TOO much, i.e. you can create a method with the same name as a property), but it shows the idea. I just subclass my ZClasses from this class, and I can customize each instance individually. [snip]
Enough for now...
Hope this helps. Gotta run. --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
Cary O'Brien wrote:
1) What is the algorithm for determining which method to call? The DTML documentation says
"attributes, including inherited and acquired attributes, of the client passed in the call to the document template are searched"
But in what order? There can be an index_html in the class, in a parent class, or somewhere up the acquisition tree. Which takes precedence?
The first two follow standard python rules, first instance attributes, then shared instance (class) attributes, then any base class attributes. THEN acquisition.
Does the product that a ZClass have anything to do with the search?
No.
What about Z-Super-Classes?
Same rules. First the instance of the ZClass attributes, then shared instance (ZClass) attributes, then any base (Z)Class attributes. THEN Acquisition.
Inquiring minds want to know.
1a) Why can't I have a method in a ZClass, but then override it in the instance?
I think your confused but I'm not sure. If your ZClass is a container (subclasses ObjectManager) then instances of that class can contain sub-objects (attributes) with names that are managable by the Zope managment interface. The managment interface will NOT however let you create a sub-object in that container that conflicts with the name of an existing attribute *including shared instance attributes like methods of YOUR ZClass*. Methods of a ZClass may look like sub-objects in a container instance, but that are not, they are shared attributes of a class, and all instances of that class will share those attributes. Now, this is a limitation/feature of the managment interface, it is not a limitation of python. If you want to assign an attribute to an instance in python that has the same name as a shared instance attribute, then that instance attribute will override the shared instance attribute.
I.E. (Gaak, it has been a while since I've had to even think about C++) virtual methods? (Or have I got that wrong).
I don't know C++.
2) It seems that the examples require the user to generate forms by hand, which seems unnecessary. For example, (after a protracted struggle with the underlying python code) I wrote a method that would create an html table for any query, ripping the column names and data out of the result object.
Ok. You're talking about SQL Methods?
2.1) Shouldn't this be a standard part of Zope?
If you're talking about SQL Methods or other objects that implement the Zope Search Inteface then it is allready a standard part of Zope.
2.2) If so, do you want this code?
You should look at what is there first and tell us how to improve it.
2.2) Likewise for property edit forms. I did find some DTML that would do this, but shouldn't this be standard.
The managment interface obviously builds the property view dynamicly, so something like this is in Zope. Whether or not it is useful to others is unknown to me. -Michel
Michel wrote:
Cary O'Brien wrote:
[snip, thanks for the explanation]
2) It seems that the examples require the user to generate forms by hand, which seems unnecessary. For example, (after a protracted struggle with the underlying python code) I wrote a method that would create an html table for any query, ripping the column names and data out of the result object.
Ok. You're talking about SQL Methods?
2.1) Shouldn't this be a standard part of Zope?
If you're talking about SQL Methods or other objects that implement the Zope Search Inteface then it is allready a standard part of Zope.
Sorry, I wasn't clear. What I was looking for was a method to get, for example, an html table out of what an ZSQL method returns. I had to look at the code under lib/python/Shared/DC/ZRDB to figure out that calling a ZSQL Method returns a Results object, and then look at the results object to see that it has methods like names(), data_dictionary() and tuples(). Then I could write a loop like... <dtml-with "Your-query-method(parameter=value, parameter=value)"> <table border=1> <tr> <dtml-in "names()"> <th><dtml-var sequence-item capitalize spacify></th> </dtml-in> </tr> <dtml-in "tuples()"> <tr> <dtml-in sequence-item> <td><dtml-var sequence-item></td> </dtml-in> </tr> </dtml-in> </table> </dtml-with> My point, I guess, is to suggest that this should be a built-in method in a ZSQL query. Unfortunately this would also hard-code the appearance of the table unless it had lots of options. I'm probably missing something.
2.2) If so, do you want this code?
You should look at what is there first and tell us how to improve it.
I did find code that kind of did this in the manage_test method in the ZRDB/DA.py file, but when called returns manage_tabs, and also access some non-dtml-accessible functions like result._serachable_result_columns(). I'm sure I'm missing something, but this doesn't seem accessible from DTML.
2.2) Likewise for property edit forms. I did find some DTML that would do this, but shouldn't this be standard.
The managment interface obviously builds the property view dynamicly, so something like this is in Zope. Whether or not it is useful to others is unknown to me.
Once again, there is code to render property table forms, but it is buried inside lib/python/OFS/properties.dtml. Once again, it seems as if a standard method to generate a form for editing properties would simplify creating applications by eliminating the need to type in, by hand, the required forms. I've seen a couple of pieces of code, both in the mailing list and on zope.org to do this. The overall goal is to make it easier for beginners to whip up an application without having to know too much about html forms and formatting. Plus to make the system easier to maintain by not having redundant information (i.e. in the property sheet or query, and also in the DTML that renders it). Thanks for your time... -- cary (obviously confused)
participants (3)
-
Cary O'Brien -
Jeff Hoffman -
Michel Pelletier