[Zope] ObjectManager example needed

Dylan Reinhardt zope at dylanreinhardt.com
Sun Nov 23 17:14:11 EST 2003


On Sun, 2003-11-23 at 01:15, Andre Meyer wrote:
> In continuing my search for help it seems like ObjectManager is what I
> am looking for in order to have a large collection of different Python
> objects in the same folder allowing for many links among them. 

Possibly... though you may do better with Folder.

> I will
> need to be able to select which kinds of items to show and sort them and
> use them in forms. That should be standard behaviour, though, I would
> expect.

It is, ex:

stuff = objectValues(obj_type)

> 
> Do you happen to have experience with ObjectManager and/or have a good
> example that I can study?

Yep.  Works like a charm.  Check out Folder and other folderish objects
in Zope (Plone, acl_users, etc).

> 
> The application I am developing is for a musician who currently has an
> Excel sheet with more than 20.000 pieces of old music (1600-1900) where
> each PieceOfMusic object refers to other objects like Composer,
> OrchestralSetting, Instrument, Cast, Recording, Writer, etc. 

OK.

> Those
> need to become different kinds of Python objects that the PieceOfMusic
> object can refer to in order to guarantee consistency. 

I'm not so sure about that, but I follow your thinking.

> 
> I assume that I need a class MusicLibrary that is a direct subclass of
> ObjectManager

Yes... or better yet, of Folder. :-)

>  and a variety of classes that represent my application
> classes

Sure.

>  and are all subclasses of ObjectManagerItem.

Probably not.  For node/leaf objects, you'll do better with SimpleItem.

>  Do you agree with
> this? In the help about ObjectManager and ObjectManagerItem I miss a
> method like manage_addObject.

Factory methods are defined by the objects they instantiate.

Getting back to the object hierarchy... for each piece of music, you
have (say) a Composer.  If you define your piece of music as a folderish
object that contains a composer object, you'll probably regret it. 
Why?  Because it's equally as valid to use Composers as a container for
specific compositions.  How many times do you want to end up
representing each composer, artist, etc?  Once, I'd bet.

Basically you have a many-to-many relationship between pieces and
composers.  In Zope, I find these are best modeled as objects in *peer*
containers.  Thus, you might have:

MusicLibrary/
   Composers/
       Verdi
   Pieces/
       Aida
       Otello

The Verdi object would then have a "pieces" property of [Aida, Otello]
and each of Verdi's operas has a "composers" property of [Verdi].

HTH,

Dylan




More information about the Zope mailing list