vendor/CMF/1.5.2/DCWorkflow

view Expression.py @ 0:e89e53b8c32e

Vendor import of CMF 1.5.2
author fguillaume
date Wed, 20 Jul 2005 16:21:26 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Expressions in a web-configurable workflow.
15 $Id: Expression.py,v 1.13.2.1 2005/04/15 09:01:32 jens Exp $
16 """
18 import Globals
19 from Globals import Persistent
20 from Acquisition import aq_inner, aq_parent
21 from AccessControl import getSecurityManager, ClassSecurityInfo
22 from DateTime import DateTime
24 from Products.CMFCore.WorkflowCore import ObjectDeleted, ObjectMoved
25 from Products.CMFCore.Expression import Expression
26 from Products.PageTemplates.Expressions import getEngine
27 from Products.PageTemplates.TALES import SafeMapping
28 from Products.PageTemplates.Expressions import SecureModuleImporter
30 class StateChangeInfo:
31 '''
32 Provides information for expressions and scripts.
33 '''
34 _date = None
36 ObjectDeleted = ObjectDeleted
37 ObjectMoved = ObjectMoved
39 security = ClassSecurityInfo()
40 security.setDefaultAccess('allow')
42 def __init__(self, object, workflow, status=None, transition=None,
43 old_state=None, new_state=None, kwargs=None):
44 if kwargs is None:
45 kwargs = {}
46 else:
47 # Don't allow mutation
48 kwargs = SafeMapping(kwargs)
49 if status is None:
50 tool = aq_parent(aq_inner(workflow))
51 status = tool.getStatusOf(workflow.id, object)
52 if status is None:
53 status = {}
54 if status:
55 # Don't allow mutation
56 status = SafeMapping(status)
57 self.object = object
58 self.workflow = workflow
59 self.old_state = old_state
60 self.new_state = new_state
61 self.transition = transition
62 self.status = status
63 self.kwargs = kwargs
65 def __getitem__(self, name):
66 if name[:1] != '_' and hasattr(self, name):
67 return getattr(self, name)
68 raise KeyError, name
70 def getHistory(self):
71 wf = self.workflow
72 tool = aq_parent(aq_inner(wf))
73 wf_id = wf.id
74 h = tool.getHistoryOf(wf_id, self.object)
75 if h:
76 return map(lambda dict: dict.copy(), h) # Don't allow mutation
77 else:
78 return ()
80 def getPortal(self):
81 ob = self.object
82 while ob is not None and not getattr(ob, '_isPortalRoot', 0):
83 ob = aq_parent(aq_inner(ob))
84 return ob
86 def getDateTime(self):
87 date = self._date
88 if not date:
89 date = self._date = DateTime()
90 return date
92 Globals.InitializeClass(StateChangeInfo)
95 def createExprContext(sci):
96 '''
97 An expression context provides names for TALES expressions.
98 '''
99 ob = sci.object
100 wf = sci.workflow
101 container = aq_parent(aq_inner(ob))
102 data = {
103 'here': ob,
104 'object': ob,
105 'container': container,
106 'folder': container,
107 'nothing': None,
108 'root': wf.getPhysicalRoot(),
109 'request': getattr( ob, 'REQUEST', None ),
110 'modules': SecureModuleImporter,
111 'user': getSecurityManager().getUser(),
112 'state_change': sci,
113 'transition': sci.transition,
114 'status': sci.status,
115 'kwargs': sci.kwargs,
116 'workflow': wf,
117 'scripts': wf.scripts,
118 }
119 return getEngine().getContext(data)