[ZPatterns] getId/setId compatibility (was Re: HowTo: Make an Image/File a DataSkin ???)

Phillip J. Eby [email protected]
Wed, 11 Jul 2001 11:07:41 -0500


Okay.  I've done a little research now...  First of all, Image and File 
don't need anything special to work with ZPatterns except the revised 
__init__ procedure you've described below.  This is because they define an 
'id()' method which is just fine by ZPatterns at present.  However, I do 
intend to change Rack to use getId() from now on, and recommend changing 
SkinScripts to use 'getId()' in place of 'id'.

And, to handle _setId() compatibility, I'm going to change 
DataSkin.__init__ to a no-op, and change Rack._RawItem() to call 
item._setId(key) after calling item._setRack(self).  This should be fully 
backward- and forward- compatible with existing code.  Of course, for 
objects like Image and File which need arguments for their __init__ 
methods, you will still have to use the workaround described below, but at 
least you won't need to worry about how/whether the 'id' is getting set 
up.  Donwside: you may have to worry about how the 'id' attribute is being 
stored, although I intend to add a trapdoor so that 'id' and '__name__' 
will automatically be stored 'persistently' if no other provider handles 
them.

At 02:26 PM 7/11/01 +0200, Ulrich Eck wrote:
> >
> > Actually, I'm not sure you need to do anything special at all.  If you use
> > the File DataSkin in a Folder w/Customizer Support, you shouldn't need to
> > do anything special, because in that mode the 'id' attribute is never used
> > by ZPatterns.
>
>What is the right way to extend an existing Class with DataSkin 
>functionality ?
>
>myclass(DataSkin,otherclass):
>or
>myclass(otherclass,DataSkin):
>
>there are often Problems with the __init__ functions that assign 
>attributes of the
>new instance were no DataManager is availiable ..
>
>usually I would do a:
>
>def addMyClass(id):
>     ob = myclass(id)
>     ob = ob.__of__(self)         # need this for the DataManager
>     ob._setup_this_instance(<myattributes>)
>     self._setOb(id,ob)
>
>and in my classes _setup_this_instance(...)
>     otherclass.__init__(<myattributes>)
>
>is this the right way to do it ??