Can't add objects to Folder-like product
Hi All, I'm trying to create some simple products. One of them starts like this: # Parsing.py from OFS.SimpleItem import Item from OFS.Folder import Folder from xml.dom import minidom from Products.Step import Step from AccessControl import ClassSecurityInfo from Globals import InitializeClass from Acquisition import Implicit from Globals import Persistent from AccessControl.Role import RoleManager class Parsing(Folder, Implicit, Persistent, RoleManager): -- Here comes the rest of the class -- I can create new objects of type Parsing. These objects also know that they are folders, so I can (through the web interface) put new objects within them. However, when I try to do this in my Python code, the troubles begin. I have this line in Parsing.py: self.manage_addProduct['OFSP'].manage_addFolder(name, title="") This gives the errors: Error Type: AttributeError Error Value: _getProducts with the backtrace: File /usr/lib/zope/lib/python/Products/Parsing/Parsing.py, line 74, in do_Steps (Object: ParseXML) File /usr/lib/zope/lib/python/App/FactoryDispatcher.py, line 99, in __getitem__ File /usr/lib/zope/lib/python/App/FactoryDispatcher.py, line 102, in __bobo_traverse__ AttributeError: (see above) I've tried to change everything I can think of, rereading the documentation a thousand times, but now I'm at a complete loss. Could someone please tell me what I could try next. Also, if I've provided too little information, please tell me what you'd need, and I'll be happy to provide it. Jesper -- Jesper Holmberg |"But how can | jesper.holmberg@enst-bretagne.fr | one be warm | ENST Br, BP 832, 29285 Brest, FRANCE | alone?" |
Jesper Holmberg wrote:
class Parsing(Folder, Implicit, Persistent, RoleManager):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You don't need any of these since Folder already subclasses them ;-)
However, when I try to do this in my Python code, the troubles begin. I have this line in Parsing.py:
self.manage_addProduct['OFSP'].manage_addFolder(name, title="")
hmmm... maybe self is acquisiton wrapped in this instance, in which case _getproducts can't be acquired. Is do_Steps called from Persing's __init__ method perhaps? cheers, Chris
Hi Chris, thanks for your prompt answer. * On Sun Nov 11, Chris Withers wrote:
class Parsing(Folder, Implicit, Persistent, RoleManager):
You don't need any of these since Folder already subclasses them ;-)
Thanks. You can tell I'm a newbie, no?
However, when I try to do this in my Python code, the troubles begin. I have this line in Parsing.py:
self.manage_addProduct['OFSP'].manage_addFolder(name, title="")
hmmm... maybe self is acquisiton wrapped in this instance, in which case _getproducts can't be acquired.
I'm afraid I don't understand what you mean by this.
Is do_Steps called from Persing's __init__ method perhaps?
Yes, that's right. I didn't know that was bad. And how would I solve this? I'd really like to add some Step elements when I create an instance of Parsing. TIA Jesper -- Jesper Holmberg |"But how can | jesper.holmberg@enst-bretagne.fr | one be warm | ENST Br, BP 832, 29285 Brest, FRANCE | alone?" |
Jesper Holmberg wrote:
Is do_Steps called from Persing's __init__ method perhaps?
Yes, that's right. I didn't know that was bad. And how would I solve this? I'd really like to add some Step elements when I create an instance of Parsing.
It's not your bad, it's just that for whatever reason, self in __init__ isn't Acquisition wrapped, which sucks :-( Anyway, I take it you have a manage_addParsing method somewhere that does something like: x = Parsing() ? In that case, change your __init__ method so it starts something like: def __init__(self,parent ...anything else you want here...): self = self.__of__(parent) and, change could line that creates the Parsing object to: x = Parsing(self,...whatever you had before...) Good luck, Chris
It's not your bad, it's just that for whatever reason, self in __init__ isn't Acquisition wrapped, which sucks :-(
Anyway, I take it you have a manage_addParsing method somewhere that does something like:
x = Parsing()
?
In that case, change your __init__ method so it starts something like:
def __init__(self,parent ...anything else you want here...): self = self.__of__(parent)
and, change could line that creates the Parsing object to:
x = Parsing(self,...whatever you had before...)
Urgh... I'd rather not do this kind of initialization in __init__, but from whatever method calls the class constructor. Standard Zope idiom would be for instance: def addMyClass(container, id, title='', REQUEST=None): """MyClass constructor.""" ob = MyClass(id, title) container._setObject(id, ob) ob = container._getOb(id) # now we have a wrapped object ob.postintialization() # do what you want in here if REQUEST is not None: REQUEST.RESPONSE.redirect(ob.absolute_url() + '/manage_main') [you'll note that I dislike calling "self" what is actually "container"] Florent -- Florent Guillaume, Nuxeo SARL (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:fg@nuxeo.com
participants (3)
-
Chris Withers -
Florent Guillaume -
Jesper Holmberg