[Zope] the PropertyManager API

Mitchell L Model mlm@acm.org
Sun, 16 Sep 2001 11:31:04 -0400


This is a longish discourse on the methods provided by PropertyManager for
manipulating properties, with suggestions for improvements.  I'd be interested
in discussion of these suggestions, historical reasons why things are the way
they are, how people use the existing API, etc.

To give this discussion some concrete context, here's how it arose.
I was writing a Python script to set up my web site.  (For various reasons I
don't want to do this manually, including wanting to be able to reorganize
things as I develop the site and generating a hierarchy of about 250 
folders and
from a text outline that defines the site structure.)  I want to set some
properties on some of the folders after I create them.

I want the script to be smart about initializing things, adding properties that
aren't there and changing properties that are.  I came up with the following
idiom, which I had to repeat in various places (and so abstracted to another
Python script).  (Uppercase names here signify arguments to that script, for
clarity here.)

     if FOLDER.hasProperty('NAME'):
         FOLDER.manage_delProperties([NAME])
     FOLDER.manage_addProperty(NAME, DESCRIPTION, TYPE)


For reference, here are the methods in PropertyManager.py:

     "public"              "private"           Web interface

     valid_property_id     _propertyMap        manage_addProperty
     hasProperty           _wrapperCheck       manage_editProperties
     getProperty           _setPropValue       manage_changeProperties
     getPropertyType       _delPropValue       manage_changePropertyTypes
     propertyIds           _setProperty        manage_delProperties
     propertyValues        _updateProperty
     propertyItems         _delProperty
     propertyMap
     propertyLabel
     propdict

I was disturbed by several things about this method collection:

     1.  Since this is an internal programmatic manipulation of the site, I
         shouldn't really be using the Web interface (though there's nothing
         wrong with it).  Yet, there's no public deleteProperty or setProperty.
         (Although there are corresponding "private" methods, there are various
         issues in using them, not all aesthetic: for instance,
         PropertyManager.py includes the public methods, but not the private
         ones, in __ac_permissions__ under 'Access contents information'.)
         Shouldn't there be public versions of _setPropValue, _setProperty,
         _delPropValue, _delProperty, and _updateProperty?

     2.  The name "update" is used for the private method, but "change" for
         the web version; these should be made consistent.

     3.  _setProperty should really have been called _addProperty, since
         that's what it does.

     4.  There are no methods in any of the three categories to do what "set"
         normally does in languages and libraries: change if there, add if not.
         I realize that this is complicated somewhat by the fact that a type is
         needed if the property is new but not if it isn't.  Nevertheless, It
         seems to me that there should be public, private, and web methods to do
         this most typical operation.  They would have to take a type argument,
         for when the property doesn't exist.  (Interesting question what it
         should do when the type argument disagrees with an existing property --
         it should probably replace the type as well as the value.)