[Zope] Set _allowed_meta_types on folder instances without creating a new product?
Dieter Maurer
dieter@handshake.de
Fri, 3 May 2002 19:05:34 +0200
Jeff Kowalczyk writes:
> > it would be very useful to apply this
> > to existing folders which are specialized in purpose, but
> > require no special class of their own.
>
> [Dieter] To apply it to existing folder, you need to redefine their
> "all_meta_types" method - in a similar spirit the "mxmObjectManager"
> did...
>
> How do I redefine a method (as opposed to setting a property) on an
> existing object?
>
> I don't want to subclass Folder into a full metatype for each
> combination of metatypes allowed, but I could see making a series of def
> methods: scripts or a product module that I could 'attach' as overrides
> to instances of regular, already created Folders as needed. Is that
> possible?
I did not meant, that you modify "all_meta_types" for each folder type
you want to restrict but that you combine the "_allowed_meta_types"
with a single modified "all_meta_types" that respects this
attribute when it is available.
Your options for such a modification:
* directly modify the source
you want to retain a patch in order to be able to apply it
to new Zope releases or you work with CVS (and its "import"
command).
* make a monkey patch (this modifies the class at initialization time)
There are documentation about this at Zope.org.
"TransparentFolder" is an example how to make a monkey patch
for "ObjectManager".
Dieter