Back to index

plone3  3.1.7
WorkflowPolicyConfig.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## CMFPlacefulWorkflow
00003 ## Copyright (C)2005 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see th e file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 Workflow Policy config
00020 """
00021 __version__ = "$Revision: 62540 $"
00022 # $Source: /cvsroot/ingeniweb/CMFPlacefulWorkflow/WorkflowPolicyConfig.py,v $
00023 # $Id: WorkflowPolicyConfig.py 62540 2008-04-12 07:50:01Z encolpe $
00024 __docformat__ = 'restructuredtext'
00025 
00026 import logging
00027 from os.path import join as path_join
00028 
00029 from Globals import InitializeClass
00030 from OFS.SimpleItem import SimpleItem
00031 from AccessControl import ClassSecurityInfo
00032 
00033 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00034 
00035 from PlacefulWorkflowTool import WorkflowPolicyConfig_id
00036 from Products.CMFPlacefulWorkflow.global_symbols import Log, LOG_DEBUG
00037 
00038 from Products.CMFCore.utils import getToolByName
00039 
00040 manage_addWorkflowPolicyConfigForm = PageTemplateFile(
00041     path_join('www', 'add_workflow_policy_config_form'), globals())
00042 def manage_addWorkflowPolicyConfig( self, REQUEST=None):
00043     ' add a Workflow Policy Configuratio into the system '
00044     workflow_policy_in = ''
00045     workflow_policy_below = ''
00046     if REQUEST:
00047         workflow_policy_in = REQUEST.get('workflow_policy_in', '')
00048         workflow_policy_below = REQUEST.get('workflow_policy_below', '')
00049 
00050     #create new workflow policy config
00051     i = WorkflowPolicyConfig(workflow_policy_in, workflow_policy_below)
00052     self._setObject( WorkflowPolicyConfig_id, i)
00053 
00054     if REQUEST is not None:
00055         REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
00056 
00057 class WorkflowPolicyConfig(SimpleItem):
00058     """Workflow policy configuration"""
00059     meta_type = 'Workflow Policy Configuration'
00060     index_html = None
00061     security = ClassSecurityInfo()
00062 
00063     manage_main = PageTemplateFile(path_join('www', 'manage_workflow_policy_config'),
00064                                    globals(),
00065                                    __name__='manage_main')
00066 
00067     manage_options=((
00068         {'icon':'', 'label':'Edit', 'action':'manage_main',},
00069         )+SimpleItem.manage_options
00070     )
00071 
00072     def __init__( self, workflow_policy_in='', workflow_policy_below='' ):
00073         """Initialize a new MailHost instance """
00074         self.id = WorkflowPolicyConfig_id
00075         self.title = "Workflow policy configuration"
00076         self.setPolicyIn(workflow_policy_in)
00077         self.setPolicyBelow(workflow_policy_below)
00078 
00079     def manage_makeChanges(self, workflow_policy_in, workflow_policy_below):
00080         """ Store the policies """
00081         self.setPolicyIn(workflow_policy_in)
00082         self.setPolicyBelow(workflow_policy_below)
00083 
00084     def getPolicyInId(self):
00085         return self.workflow_policy_in
00086 
00087     def getPolicyBelowId(self):
00088         return  self.workflow_policy_below
00089 
00090     def getPolicyIn(self):
00091         pwt = getToolByName(self, 'portal_placeful_workflow')
00092         wfp_id = self.getPolicyInId()
00093         policy_in = pwt.getWorkflowPolicyById(wfp_id)
00094         return policy_in
00095 
00096     def getPolicyBelow(self):
00097         pwt = getToolByName(self, 'portal_placeful_workflow')
00098         wfp_id = self.getPolicyBelowId()
00099         policy_below = pwt.getWorkflowPolicyById(wfp_id)
00100         return policy_below
00101 
00102     def setPolicyIn(self, policy):
00103         if not type(policy) == type(''):
00104             raise ValueError, "Policy must be a string"
00105         self.workflow_policy_in = policy
00106 
00107     def setPolicyBelow(self, policy):
00108         if not type(policy) == type(''):
00109             raise ValueError, "Policy must be a string"
00110         self.workflow_policy_below = policy
00111 
00112     def getPlacefulChainFor(self, portal_type, start_here=False):
00113         """Get the chain for the given portal_type.
00114 
00115         Returns None if no placeful chain is found.
00116         Does _not_ acquire from parent configurations.
00117 
00118         Usecases:
00119         If the policy config is in the object that request the chain we cannot
00120         take the 'below' policy.
00121         In other case we test the 'below' policy first and, if there's no chain
00122         found, the 'in' policy.
00123         """
00124         workflow_tool = getToolByName(self, 'portal_placeful_workflow')
00125         Log(LOG_DEBUG, 'below policy id', self.getPolicyBelowId())
00126         Log(LOG_DEBUG, 'in policy id', self.getPolicyInId())
00127 
00128         chain = None
00129         policy = None
00130         if not start_here:
00131             policy = workflow_tool.getWorkflowPolicyById(self.getPolicyBelowId())
00132             # print "start here:", start_here, "type", portal_type, "policy", policy
00133             if policy != None:
00134                 chain = policy.getChainFor(portal_type)
00135 
00136         policy = workflow_tool.getWorkflowPolicyById(self.getPolicyInId())
00137         # print "start here:", start_here, "type", portal_type, "policy", policy
00138 
00139         Log(LOG_DEBUG, "policy", repr(policy), policy != None)
00140         if chain == None and policy != None:
00141             chain = policy.getChainFor(portal_type)
00142             Log(LOG_DEBUG, "portal_type and chain", portal_type, chain)
00143 
00144         return chain
00145 
00146 InitializeClass( WorkflowPolicyConfig )