quick search:

Move object in DCWorkflow

Submitted by: runyaga
Last Edited: 2002-09-20

Category: CMF

Average rating is: 5.0 out of 5 (2 ratings)

One of the most common things done using Workflow in CMF is moving objects around on some transition. Here is a simple recipe that will move only News Item objects to a folder.

Source (Text):
#in the root of your CMF site create a folder with id, news
#select portal_workflow, see what workflow is being use for News Item
#look in the contents tabs and select the workflow you want to change
#goto the scripts tab
#create a Script(Python) with the id moveOnPublish
o=getattr(state_change, 'object')

if o.getTypeInfo().getId()=='News Item':
    portal_root.Members.manage_pasteObjects( obj_parent.manage_cutObjects(o.getId()) )

#now goto the transitions tab and select the publish tranisition
#in the Script (After) select 'moveOnPublish'
#Save Changes

#finally we need to apply the new changes to items that
#use this workflow - this is not necessary but a good habit to form.
#click on portal_workflow and in the Workflow tab click the 
#Update Security Settings button. 

# I was having problems doing this when a Member didnt have access
# to the destination folder (where we are pasting objects)
# so to properly do this I had to create an External Method
# this is the external method and I just call it.
# the destination is a reference to the folderish object you want to
# paste the object.

from Products.CMFCore.utils import getToolByName
from AccessControl import getSecurityManager

def move_pending(self, state_change):

    membershiptool=getToolByName(self, 'portal_membership')

    membershiptool.setLocalRoles(dest, (member,), 'Owner', reindex=0)
    dest.manage_pasteObjects( parent.manage_copyObjects( obj.getId() ))
    membershiptool.deleteLocalRoles(dest, (member,), reindex=0)

# its really lame, you have set local roles on the object, then
# perform the paste/action and then remove the local roles.
# the upside is everything is transactional, the downside is
# manage_pasteObjects() is broken and should be fixed.

check out http://www.zope.org/Members/hathawsh/DCWorkflow_docs
for more information on DCWorkflow also the Expressions.stx file
in the DCWorkflow Product.

after you have completed this recipe. you will be on your way
to Workflow nirvana. you will notice some things such as
inside a Script(Python) some excpetions are swallowed as to not
interfere with the user experience. you will get a feel for these
after some trial and error.

- You will want to understand that states are permissions set for an object.
- Transitions allow for you to hook before/after the tranistion occurs (permissions are applied)
- Worklists are how people will see the objects in the workflow
- Variables are ways to see into Workflow.

Hats off to Zope Corp. for releasing this product. It certainly
makes CMF a excellent product for 99% of the workflow situations
you will encounter. You may also want to search for OpenFlow, an
activity based engine. It is not yet wired into the CMF.


Use one script for many types of objects. by rroeber - 2002-08-22
## a little twist to this great script will
## allow you to map a 'News Item' to the folder 'newsitems',
## an 'Image' to the folder 'graphics', and so on.

o=getattr(state_change, 'object')
content_type = o.getTypeInfo().getId()

mappings = {'News Item' : 'newsitems'
            ,'Image'    : 'graphics'
            . . .

if content_type in mappings.keys():
    portal_root[mappings[content_type]].manage_pasteObjects( obj_parent.manage_cutObjects(o.getId()) )
Can't move news item with Plone 1.0a2 by dhart - 2002-08-22
Using Zope 2.5.1, CMF 1.3, Plone 1.0a2

Publishing news items results in error:

 The object News_Item.2002-08-07.4925 does not support this operation