[Zope-CMF] child class behaves like PortalFolder
Jens Wolk
jewo_lists@gmx.de
Sun, 24 Mar 2002 20:01:24 +0100
Am Mittwoch, 20. März 2002 15:31 schrieb Tres Seaver:
> Jens Wolk wrote:
> > Am Mittwoch, 20. März 2002 13:28 schrieben Sie:
> >
> > [...]
> >
> >> > However, my folderish "CMF zyp Category" behaves like it was a
> >> > PortalFolder (its parent class) and I don't know why. (If I - for
> >> > example - click on "Edit" for the object myZypCategory then
> >> > myZypCategory/folder_edit_form is called instead of
> >> > myZypCategory/zyp_category_edit_form)
[...]
> Somehow the 'portal_type' of your instances is not being set;
> are you creating them via the stock 'folder_factories' form?
> Or are these objects created by some other process?
I'm not sure if I understand the question correctly. I create the instances
through the ZMI (or the "folder contents" view of the folder in which the
instances are located), so this means, they are created by the
'folder_factories' form, right? Creating by another process would for example
mean in a Python script, is that so?
> As a check,
> use your browser to call the 'Type' method of one of your objects
> (i.e., append '/Type' to the URL): I am sure it will return "Folder".
Correct.
> If you aren't constructing instances of your type via 'invokeFactory'
> on its container, then you likely need to mimic what it does; in
> particular, you will need to call '_setPortalTypeName' on the new
> instance. If you don't intend for your class ever to be used as a
> base for more than one type, you could also add a shared attribute,
> 'portal_type', to the class, e.g.::
>
> class zypCategory (PortalFolder, DefaultDublinCoreImpl):
> """
> a zyp category
> """
>
> meta_type = 'CMF zyp Category'
> portal_type = 'zypCategory'
> #...
This solution works. There seems to be another solution which I saw in the
"CMFArticle" product (call manage_afterAdd of parent class PortalFolder).
class zypCategory (PortalFolder, DefaultDublinCoreImpl):
"""
a zyp category
"""
meta_type = 'CMF zyp Category'
#...
security.declarePrivate('manage_afterAdd')
def manage_afterAdd(self, item, container):
" Add self to the workflow and catalog. "
# Recurse in the children (ObjectManager)
PortalFolder.manage_afterAdd(self, item, container)
#...
That way it should still be possible to use the zypCategory class as base
class for other classes, shouldn't it?
With CMF and Zope, I feel more or less like a coding monkey: copying code
from others without understanding what's going on behind the scenes :-/
But with the encouraging support like yours, Tres, this situation will
hopefully soon improve. :)
Jens