Hi, I've a product that defines a classe ageForm. I've a PythonScript that adds an ageForm instance to a folder. After adding the instance it calls a method on it. This methods tries to access an objects using acquisition. Image I have something like this: + f (Folder) + o (object to acquire) + i (ageForm istance) + s (script that creates i and calls i.m) so the script s is like this: i = f.manageAddForlder ..... i.m () the ageForm method is like this: def m(self): o.doSomething() the ageForm class inherits from SimpleItem.SimpleItem and from a simple Python base class. Any hint? TIA, Luca
Hello, I think this is what you need: http://www.zopelabs.com/cookbook/1001368850 m Luca Manini wrote:
Hi,
I've a product that defines a classe ageForm. I've a PythonScript that adds an ageForm instance to a folder. After adding the instance it calls a method on it. This methods tries to access an objects using acquisition.
Image I have something like this:
+ f (Folder) + o (object to acquire) + i (ageForm istance) + s (script that creates i and calls i.m)
so the script s is like this:
i = f.manageAddForlder ..... i.m ()
the ageForm method is like this:
def m(self): o.doSomething()
the ageForm class inherits from SimpleItem.SimpleItem and from a simple Python base class.
Any hint? TIA, Luca
Luca Manini writes:
I've a product that defines a classe ageForm. I've a PythonScript that adds an ageForm instance to a folder. After adding the instance it calls a method on it. This methods tries to access an objects using acquisition. ... Apparently, you do not tell us what your problem is...
I expect, the problems cause is that constructors in Zope usually do not return the constructed object (but either "None" or the id of the constructed object). The standard idiom is: om.manage_addProduct[<product_name>].<constructor>(id,....) obj= getattr(om,id) Dieter
On Thu, 2 May 2002, Dieter Maurer wrote:
Luca Manini writes:
I've a product that defines a classe ageForm. I've a PythonScript that adds an ageForm instance to a folder. After adding the instance it calls a method on it. This methods tries to access an objects using acquisition. ... Apparently, you do not tell us what your problem is...
I expect, the problems cause is that constructors in Zope usually do not return the constructed object (but either "None" or the id of the constructed object).
The standard idiom is:
om.manage_addProduct[<product_name>].<constructor>(id,....) obj= getattr(om,id) I tried it this way and it works perfectly if the new object is a folder or a dtml-document, but not for a tinytable object. A complete very simple example you can find at:
http://www.foodborne-net.de/~tillea/MyFolder/MyFolder.tgz The relevant part is shown here: ob=MyFolder() ob.id=str(id) ob.title=title self._setObject(id, ob) ob=self._getOb(id) checkPermission=getSecurityManager().checkPermission ### From the example ... but does not work anyway ## ob = getattr(self, id) #we basically get the instance from the ZODB, now has AqWrapper ob.manage_addFolder('someid') #works as expected ob.manage_addTinyTable(id='link_table', title='TinyTableObject for '+ob.id, columns=column_names) The last line does not work because it does not put the TinyTable object into the new folder (where I was able to create the example folder named 'someid' but it will be created in the folder below. Is this perhaps a TinyTable bug? Kind regards Andreas.
Tille, Andreas writes:
On Thu, 2 May 2002, Dieter Maurer wrote:
The standard idiom is:
om.manage_addProduct[<product_name>].<constructor>(id,....) obj= getattr(om,id) I tried it this way and it works perfectly if the new object is a folder or a dtml-document, but not for a tinytable object. ... The relevant part is shown here:
ob=MyFolder() ob.id=str(id) ob.title=title self._setObject(id, ob) ob=self._getOb(id) ...
### From the example ... but does not work anyway ## ob = getattr(self, id) #we basically get the instance from the ZODB, now has AqWrapper
ob.manage_addFolder('someid') #works as expected ob.manage_addTinyTable(id='link_table', title='TinyTableObject for '+ob.id, columns=column_names)
The last line does not work because it does not put the TinyTable object into the new folder (where I was able to create the example folder named 'someid' but it will be created in the folder below. I expect this is because your "ob" does not have a "manage_addTinyTable" method but instead acquires it from "self". It is then this "self" that is passed in to "manage_addTinyTable" as first argument and gets the new tiny table.
Probably, "TinyTable" uses old style initialization (see mailing list archive for an explanation). This would mean, it installs its constructors directly as so called folder methods in "OFS.Folder". Only classes derived from "OFS.Folder" have these constructors. You may try the official idiom to instantiate classes: ob.manage_addProduct['TinyTable'].manage_addTinyTable(...) I expect it to work even with old style initialization but I am not sure. If it does not work, converting the TinyTable to use new style initialization would probably the best way (again: the mailing list archives will tell you what's the difference). Dieter
On Tue, 7 May 2002, Dieter Maurer wrote:
Tille, Andreas writes:
### From the example ... but does not work anyway ## ob = getattr(self, id) #we basically get the instance from the ZODB, now has AqWrapper
ob.manage_addFolder('someid') #works as expected ob.manage_addTinyTable(id='link_table', title='TinyTableObject for '+ob.id, columns=column_names)
The last line does not work because it does not put the TinyTable object into the new folder (where I was able to create the example folder named 'someid' but it will be created in the folder below. I expect this is because your "ob" does not have a "manage_addTinyTable" method but instead acquires it from "self". It is then this "self" that is passed in to "manage_addTinyTable" as first argument and gets the new tiny table.
Probably, "TinyTable" uses old style initialization (see mailing list archive for an explanation). This would mean, it installs its constructors directly as so called folder methods in "OFS.Folder". Only classes derived from "OFS.Folder" have these constructors.
You may try the official idiom to instantiate classes:
ob.manage_addProduct['TinyTable'].manage_addTinyTable(...)
I expect it to work even with old style initialization but I am not sure. I t worked not for me this way.
If it does not work, converting the TinyTable to use new style initialization would probably the best way (again: the mailing list archives will tell you what's the difference). Once I was told that even if Tinytable has the status
Release Version Date Size TinyTable Beta 2 (Development) 1999/09/20 11376 bytes shown at http://www.zope.org/Members/tsarna/TinyTable it is not changed any more because it is thus stable. My remark that at least the web page has a bug (it should be declared "stable" and not Beta if it is *stable*) was ignored so far. Obviousely it now shows that there could be some work done if I do understand Dieters remarks right. As usually in Free Software development someone might say: "Do it yourself if you want it to be done." and this is OK for me. But I use it in a quite low priority project and do not have time (to require enough knowledge via Mailing archive or other resources nor to do the exact fix) currently. So take it please as a kind hint to an open bug in the TinyTable product. I could even bother the Debian Bug Tracking System with this problem - but I guess the Debian-Maintainer would do the same like me - just ask you people whether someone likes to continue developing. The same applies for the TInyTablePlus product. Kind regards Andreas. PS: I was talking about the complete example available at: http://www.foodborne-net.de/~tillea/MyFolder/MyFolder.tgz
participants (4)
-
Dieter Maurer -
Luca Manini -
marci -
Tille, Andreas