[Zope] inheritedAttribute doesn't seem to work
Matt
matt@inuan.com
Mon, 28 Jul 2003 15:24:38 +1200
inheritedAttribute does not seem to work for me. The situation is
summarized as follows
I have the following module in a the std python path
/usr/local/lib/python/site-packages/PackageA/ModuleA
ModuleA defines 20 different classes, and factory methods to generate
instances of these.
In a zope product in zope/lib/python/Products/MyProduct I have the
following in MyProduct.py
from PackageA import ModuleA
class MyProduct( Folder.Folder, Persistent, Implicit ):
blah ( manage options, security, metatype etc)
def __init__(self, id, title, name ):
self.id = id
self.title = title
self.name = name
self.dataModels = []
def addModel( self, textData ):
"""Add some data"""
self.dataModels.append( Data( textData ) )
self._p_changed = 1
class Data:
blah (security)
def __init__( self, dataText ):
self.dataModel = ModuleA.generateModel( dataText )
the generateModel( dataText ) is a text parser, and factory locator and
caller.
To get secirty settings into the 20 or so Classes in ModuleA I needed to
proxy them in the product here. The model that is generated is basically
a directed acyclic graph, with one top node, which is an object of type
Model. The proxy object for model looks like the following
class ModelProxy( ModuleA.model ):
blah( security settings)
def __init__( self, attributeDict, parentObject ):
ModuleA.model.__init__( self, attributeDict, parentObject )
# attributeDict, parentObject are simply attributed that are
passed by the text parser
# to construct in this case a Model object
This all works fine, and I end up with happily constructed models in the
dataModels attribute of MyProduct with all nodes of the graph accessable
to python scripts. But then I decided that since I opened up these
models to be accessed through python scripting, i.e. the reason for the
security proxy objects in the first place, then I should clean up the
persistence parts so that changes to the model objects are persisted.
I thought adding Persistent into the proxy objects for the 20 different
kinds of classes would be sufficient, and of course ran into the "Error
Value: unbound method __init__() must be called with instance as first
argument" problem.
To solve this I tried the following replacement for ModelProxy (and
similarly for all the others)
class ModelProxy( Persistent, ModuleA.model ):
blah( security settings)
def __init__( self, attributeDict, parentObject ):
Persistent.inheritedAttribute('__init__')( self, attributeDict,
parentObject )
but still got the error.
I even tried
class ModelProxy( Persistent, ModuleA.model ):
blah( security settings)
_model__init__ = ModuleA.model.__init__
def __init__( self, attributeDict, parentObject ):
ModelProxy._model__init__( self, attributeDict, parentObject )
# or self._model__init__( attributeDict, parentObject )
and still got the same error.
Does anyone have any ideas what may be wrong?
I am also interested whether simply making the different objects(which
are nodes in the DAG) persistent is enough to signal all the way back up
MyProduct that self.dataModel has changed when one of the nodes deep in
the graph has changed.
regards
Matt