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

Alex Clark aclark at aclark.net
Mon Mar 30 12:00:01 UTC 2009


On 2009-03-30, Raphael Ritz <r.ritz at biologie.hu-berlin.de> wrote:
> Alex Clark wrote:
>
> Hi Alex,
>
>
>> On 2009-03-12, Hedley Roos <hedley at upfrontsystems.co.za> wrote:
>>> 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)
>> 
>> This is great! Thanks, Hedley (and all, for the replies).
>> 
>> I'm very close but hitting some annoying roadblock, any thoughts on:
>>     - http://paste.plone.org/27262
>> 
>> With code:
>>     - http://tinyurl.com/chm3f9
>
> Looking at this I just noticed the following:
>
> [..]
>      review_state = wf.getInfoFor(todo, 'review_state')
>      path = todo.absolute_url_path()
>
>      for brain in catalog.searchResults(path=path, portal_type='Todo item'):
>          obj = brain.getObject()
>          obj_path = obj.absolute_url_path()
>          old_state = event.old_state.getId()
>          log('Changing workflow state on %s from %s to %s.' % (obj_path, 
> old_state, review_state))
>          wf.doActionFor(obj,review_state,wf_id='todo_list_workflow')
> [..]
>
> Note that you are passing a review *state* to 'doActionFor'
> whereas you are supposed to specify a *transition*.

Thanks!

>
> Raphael
>
>
>> 
>> ?
>> 
>> I'm starting to suspect my workflow is broken, after poking around
>> Module Products.DCWorkflow.DCWorkflow, line 283, in doActionFor
>> it raises:
>>     raise WorkflowException(_(u'Object is in an undefined state.'))
>> which makes no sense to me.
>> 
>>> Hedley
>> 


-- 
Alex Clark · http://aclark.net
Buy Practical Plone 3: http://tinyurl.com/practical-plone





More information about the Product-Developers mailing list