We still have no easy way to use add views for CMF content. I tried to figure out what needs to be done to make CMF content creation more generic and to avoid duplicate notifyWorkflowCreated and (re)indexObject calls.

CMF uses two kinds of factories:

Oldstyle factories are used by FactoryTypeInformation if 'product' is specified and by ScriptableTypeInformation. They are black box factory methods that create unfinished content (no portal type set) and add it to the container.

Newstyle factories are used by FactoryTypeInformation if 'product' is not specified. They are zope 3 style factories. The code using these factories is responsible for setting the portal type and adding the content object to its container.

Both currently depend on the _finishConstruction() process that sets the portal type and calls notifyWorkflowCreated() and reindexObject().

Here are my assertions:

a) The right place for calling notifyWorkflowCreated() and indexObject() is the event handler for IObjectAddedEvent. _setObject() sends this event by default.

b) Oldstyle factory methods are not responsible for setting the portal type. They call _setObject() to early for sending IObjectAddedEvent because the portal type might be wrong at that moment.

Proposed changes:

1.) Let's get rid of _finishConstruction(): Using newstyle factories we should set the portal type *before* calling _setObject(). notifyWorkflowCreated() and reindexObject() should be called by the event handler.

2.) Fix *all* oldstyle factories: They don't finish content creation, so they should not send the events. Since ScriptableTypeInformation factory methods don't call _setObject() directly, this affects only file system code.
    self._setObject(id, o)
Has to be replaced by:
    self._setObject(id, o, suppress_events=True)
In each factory of each third party content type. I don't like that, but it is the only solution I see that allows us to use the events correctly.

3.) For oldstyle factories, set the portal type after calling the factory and send events after that. Unfortunately We can't send the IObjectWillBeAddedEvent because we don't know the object before it is added.

4.) For newstyle factories, also set the portal type, but let _setObject() send the events.

5.) Modify handleContentishEvent(): Add the notifyWorkflowCreated() call for IObjectAddedEvent. indexObject() is already called.

Any comments? Questions? Objections?



Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to