[Zope] ZClasses question

ra@burningman.com ra@burningman.com
Thu, 07 Feb 2002 11:02:01 -0800


David Thibault wrote:

> Hello all,
> 
> I would like to make a zclass that contains a set of folders & dtml
> docs/methods/etc.  I would like to create a "group folder" for the various
> depts and teams at my organization for the intranet site.  I would like to
> use zclasses because I would like to be able to edit the default
> functionality set of each department/team's folder (like adding a document
> library, new style index_html, etc) once (in the zclass) and have it cascade
> throughout each team/department folder.


I'm doing a very similar thing, building an extranet for the Burning Man 
organization to allow the volunteer teams to manage themselves.


> Am I on the right track here?  Can zclasses behave this way?  I'm totally
> new to zclasses, although I have done quite a bit with Zope/dtml/python so
> far.  I just haven't been taking advantage of Zope's object-orientedness.
> Any good tutorials specific to this type of ZClass usage would also be
> appreciated.


I think that you are on the right track.  There are few things to watch 
out for, though.  I'll tell you what I've learned:

- As far as methods go, this is exactly what you want.  You can put your 
index_html (or any other) method into the ZClass, and any changes you 
make to it will be instantly propagated out to all of the instances.

- Properties play nice, as well... if you add a new property to the 
ZClass, it will become a property for all of the instances, assuming 
whatever default value you specify in the ZClass.  Of course, you'll 
need to visit each instance by hand to set these values to something 
appropriate for that instance, if the default won't do.

- Things get trickier when you get to objects contained WITHIN your 
ZClass.  It sounds to me like you want to subclass from ZFolder, so that 
you can browse into each team's folder and add things.  There's no way 
that I know of to do this in the ZClass's definition itself... what 
you'll need to do is to modify the constructor method of the ZClass to 
instantiate these new sub-objects.

That last one bears more explanation:  Say you want each of your teams 
to have a ZWiki in their folder.  This isn't a property or method of 
your ZClass, it's an object contained within each instance of your 
ZClass, which you can do because your ZClass inherits from ZFolder which 
inherit from ObjectManager.  You have to change your ZClass's 
constructor method so that a new ZWiki gets created and added to your 
ZClass at creation time.

This has a drawback, though, because these sorts of changes won't be 
propagated to the existing instances like the method or property changes 
will.  What we've decided to do was to have all the work that the 
constructor method does delegated out to other methods.  Then, if we 
need to add a new subobject to every existing instance of our ZClass, we 
could easily write a PythonScript that iterates through the extranet 
tree and then calls this little delegation method to add the sub-objects 
in a consistent manner.  Newly created objects would get this method 
called at construction time, and all would be well in the world.

I don't know if you're using a SQL database at all, but if you are, you 
might want to look at ZPatterns.  It'll make your brain hurt for a 
while, but once you figure out how to make it work for you, it'll make 
things very nice.  I've got the properties of our ZClass coming directly 
out of the SQL database, and the UI code has no idea that this is even 
happening.

Good luck,

-r