[Zope-dev] adding properties to instances v. classes

Jamie Heilman jamie@audible.transient.net
Thu, 21 Nov 2002 11:46:53 -0800


> An additional declaration might help, something like
> "_addableProperties". Names specified in this sequence could be
> allowed as property names unless the instance (itself) already has
> an attribute of this name.  Of course, something like this needs to
> be implemented and is currently not available.

OK, let me offer a specific example, currently the height and width
properties of an Image object are removable from the ZMI.  If you do
that though, you can't add them back.  Its sorta silly.  What I was
about to play with was simply removing the the height and width class
variables from the Image class and replacing where they are initially
set up and modified when a new image is uploaded in udpate_data(),
with something like:

        if width >= 0 and height >= 0:
            if self.hasProperty('width'):
                self.manage_changeProperties(width=width)
            else:
                self.manage_addProperty('width', width, 'string')
            if self.hasProperty('height'):
                self.manage_changeProperties(height=height)
            else:
                self.manage_addProperty('height', height, 'string')

Unless I'm missing something, which is entirely possible, I haven't
tested this yet and I'm about to go to bed so I probably won't until
sometime tomarrow, but I think this might let height and width
properties be freely removed and re-added without any bad side
effects.  I'll probably have to kick the tag() function some to make
it transparent, but that seems to be typical as the tag() function is
just something of an impurity.

-- 
Jamie Heilman                   http://audible.transient.net/~jamie/
"You came all this way, without saying squat, and now you're trying
 to tell me a '56 Chevy can beat a '47 Buick in a dead quarter mile?
 I liked you better when you weren't saying squat kid."	-Buddy