I have a folderish content-type that accepts other 'Folder' objects as subjects. I need to attach folder restrictions to newly created Folders . In side a handler for IObjectCreatedEvent I can get hold of the related folder instance however the folder instance is not acquisition-wrapped or not finally constructed in order get hold of the parent for performing some further checks. Is there a different way hooking into the Dexterity content-type creation cycle?
How about def _setObject in the container class?
Dexterity's addContentToContainer (and createContentInContainer) call container._setObject
Or, use IObjectAddedEvent which should have event.newParent
Then obj should be aq wrapped, or you can do it yourself with __of__:
def handle(obj, event):
aq_wrapped = obj.__of__(event.newParent)
IObjectAddedEvent could work.
There is duplicate and inconsistent and incomplete documentation on events here.
In corner cases where I have been unable to use IObjectAddedEvent, IIRC, I have resorted in IObjectCreatedEvent subscribers to obtaining the parent folder from the request object, obtained via zope.globalrequest.getRequest(). This is not pretty; it is a last resort for peculiar situations.
Yep; the object hasn't been added to the tree when ObjectCreated fires. Therefor no acquisition yet.
IObjectAddedEvent did the job.
Code of Conduct –
Hosting courtesy of Rackspace