[Product-Developers] Re: How to change workflow states on all objects in a container?

Hedley Roos hedley at upfrontsystems.co.za
Thu Mar 12 08:49:28 UTC 2009


>> In Products.todo (https://svn.plone.org/svn/collective/Products.todo/trunk)
>> I have a folderish 'Todo Item' content type that can contain one or more 'Todo Item'(s). 
>>
>> I've just added a workflow that contains states: 'not done', 'done' and when state
>> is changed on a todo item with todo items inside of it, I want to change state
>> for all of those objects. 
>>
>> What is the best way to do that?
>>

I would use an event subscriber:

   <subscriber
     for="Products.todo.content.interfaces.ITodo
          Products.DCWorkflow.interfaces.IAfterTransitionEvent"
     handler=".events.afterTransitionTodo"
   />

def afterTransitionTodo(todo, event):
   wf = getToolByName(todo, 'portal_workflow')
   new_state = wf.getInfoFor(todo, 'review_state')   # xxx: the state is 
probably if the event parameter, not sure
   for obj in todo.getFolderContents(full_objects=True):
     obj.doActionFor(obj, new_state)

Hedley




More information about the Product-Developers mailing list