Back to index

plone3  3.1.7
workflow.py
Go to the documentation of this file.
00001 ##################################################################
00002 #
00003 # (C) Copyright 2006-2007 ObjectRealms, LLC
00004 # All Rights Reserved
00005 #
00006 # This file is part of iterate.
00007 #
00008 # iterate is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # iterate is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with CMFDeployment; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 ##################################################################
00022 """
00023 $Id: workflow.py 1824 2007-02-08 17:59:41Z hazmat $
00024 
00025 Applies new checkout specific workflows to content that is checked out.
00026 
00027 """
00028 
00029 from Acquisition import aq_base
00030 from Products.CMFCore.utils import getToolByName
00031 from Products.CMFPlacefulWorkflow.WorkflowPolicyConfig import WorkflowPolicyConfig
00032 from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import WorkflowPolicyConfig_id
00033 from plone.app.iterate.util import get_storage
00034 
00035 USE_WORKFLOW = "checkout_workflow_policy"
00036 
00037 policy_storage = "previous_wf_policy"
00038 
00039 def handleCheckout( event ):
00040     # defer to setting
00041     properties = getToolByName(aq_base(event.object), 'portal_properties')
00042     enabled = properties.site_properties.getProperty('enable_checkout_workflow')
00043     if not enabled:
00044         return
00045 
00046     policy_id = properties.site_properties.getProperty('checkout_workflow_policy')
00047     
00048     existing_policy = getattr( aq_base( event.working_copy ), WorkflowPolicyConfig_id, None )
00049     storage = get_storage( event.relation )
00050     
00051     # set config for policy in and below 
00052     policy = WorkflowPolicyConfig( policy_id, policy_id)
00053     policy.coci_created = True
00054     
00055     if existing_policy is not None:
00056         storage[ policy_storage ] = policy
00057 
00058     # we setattr because we want the effect on non containerish objects
00059     setattr( event.working_copy, WorkflowPolicyConfig_id, policy )
00060 
00061 def handleCheckin( event ):
00062     policy = getattr( aq_base(event.object), WorkflowPolicyConfig_id, None )
00063     storage = get_storage( event.relation )
00064     previous_policy = storage.get( policy_storage )
00065     if previous_policy is None:
00066         if policy and not policy.coci_created:  # only reset workflows we know.. could use are own storage
00067             return
00068         elif policy is None:
00069             return
00070         else:
00071             delattr( event.object, WorkflowPolicyConfig_id )
00072     else:
00073         setattr( event.object, WorkflowPolicyConfig_id, previous_policy)
00074     
00075 
00076 
00077