Automatically do stuff when object is created
I needed to add two new folders inside each Shop Item content type object when they were created. This worked in P4.3.7, despite the info being for P5
I need to create two image folders inside each Shop Item as they are created.
I created a subscriber via Products.SimpleShopping/Products/SimpleShopping.configure.zcml
<subscriber for=".content.interfaces.IShopItem Products.Archetypes.interfaces.IObjectInitializedEvent" handler=".browser.automated_actions.add_image_folders" />
The then created the automated_actions.py module in browser with the following method:
def add_image_folders(obj, event): from Products.CMFCore.utils import getToolByName wftool = getToolByName(obj, 'portal_workflow') obj.invokeFactory(type_name='Folder',id='product-images',title='Product images') obj.invokeFactory(type_name='Folder',id='product-icons',title='Product icons') container = obj['product-icons'] wftool.doActionFor(container, 'publish') container = obj['product-images'] wftool.doActionFor(container, 'publish')
And it then worked! All the info came from here. Which will be useful if I start using Dexterity types.
Document Actions




{Built on Planet Plone}