vendor/CMF/1.6.1/DCWorkflow

view Variables.py @ 0:238bab7e7116

CMF 1.6.1 vendor import
author fguillaume
date Tue, 13 Jun 2006 14:57:59 +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 """ Variables in a web-configurable workflow.
15 $Id: Variables.py 36910 2005-04-07 16:37:47Z yuppie $
16 """
18 from AccessControl import ClassSecurityInfo
19 from Acquisition import aq_inner
20 from Acquisition import aq_parent
21 from Globals import DTMLFile
22 from Globals import InitializeClass
23 from OFS.SimpleItem import SimpleItem
25 from ContainerTab import ContainerTab
26 from Expression import Expression
27 from Guard import Guard
28 from permissions import ManagePortal
29 from utils import _dtmldir
32 class VariableDefinition(SimpleItem):
33 """Variable definition"""
35 meta_type = 'Workflow Variable'
37 security = ClassSecurityInfo()
38 security.declareObjectProtected(ManagePortal)
40 description = ''
41 for_catalog = 1
42 for_status = 1
43 default_value = ''
44 default_expr = None # Overrides default_value if set
45 info_guard = None
46 update_always = 1
48 manage_options = (
49 {'label': 'Properties', 'action': 'manage_properties'},
50 )
52 def __init__(self, id):
53 self.id = id
55 def getDefaultExprText(self):
56 if not self.default_expr:
57 return ''
58 else:
59 return self.default_expr.text
61 def getInfoGuard(self):
62 if self.info_guard is not None:
63 return self.info_guard
64 else:
65 return Guard().__of__(self) # Create a temporary guard.
67 def getInfoGuardSummary(self):
68 res = None
69 if self.info_guard is not None:
70 res = self.info_guard.getSummary()
71 return res
73 _properties_form = DTMLFile('variable_properties', _dtmldir)
75 def manage_properties(self, REQUEST, manage_tabs_message=None):
76 '''
77 '''
78 return self._properties_form(REQUEST,
79 management_view='Properties',
80 manage_tabs_message=manage_tabs_message,
81 )
83 def setProperties(self, description,
84 default_value='', default_expr='',
85 for_catalog=0, for_status=0,
86 update_always=0,
87 props=None, REQUEST=None):
88 '''
89 '''
90 self.description = str(description)
91 self.default_value = str(default_value)
92 if default_expr:
93 self.default_expr = Expression(default_expr)
94 else:
95 self.default_expr = None
97 g = Guard()
98 if g.changeFromProperties(props or REQUEST):
99 self.info_guard = g
100 else:
101 self.info_guard = None
102 self.for_catalog = bool(for_catalog)
103 self.for_status = bool(for_status)
104 self.update_always = bool(update_always)
105 if REQUEST is not None:
106 return self.manage_properties(REQUEST, 'Properties changed.')
108 InitializeClass(VariableDefinition)
111 class Variables(ContainerTab):
112 """A container for variable definitions"""
114 meta_type = 'Workflow Variables'
116 all_meta_types = ({'name':VariableDefinition.meta_type,
117 'action':'addVariable',
118 },)
120 _manage_variables = DTMLFile('variables', _dtmldir)
122 def manage_main(self, REQUEST, manage_tabs_message=None):
123 '''
124 '''
125 return self._manage_variables(
126 REQUEST,
127 management_view='Variables',
128 manage_tabs_message=manage_tabs_message,
129 )
131 def addVariable(self, id, REQUEST=None):
132 '''
133 '''
134 vdef = VariableDefinition(id)
135 self._setObject(id, vdef)
136 if REQUEST is not None:
137 return self.manage_main(REQUEST, 'Variable added.')
139 def deleteVariables(self, ids, REQUEST=None):
140 '''
141 '''
142 for id in ids:
143 self._delObject(id)
144 if REQUEST is not None:
145 return self.manage_main(REQUEST, 'Variable(s) removed.')
147 def _checkId(self, id, allow_dup=0):
148 wf_def = aq_parent(aq_inner(self))
149 if id == wf_def.state_var:
150 raise 'Bad Request', '"%s" is used for keeping state.' % id
151 return ContainerTab._checkId(self, id, allow_dup)
153 def getStateVar(self):
154 wf_def = aq_parent(aq_inner(self))
155 return wf_def.state_var
157 def setStateVar(self, id, REQUEST=None):
158 '''
159 '''
160 wf_def = aq_parent(aq_inner(self))
161 if id != wf_def.state_var:
162 self._checkId(id)
163 wf_def.state_var = str(id)
164 if REQUEST is not None:
165 return self.manage_main(REQUEST, 'Set state variable.')
167 InitializeClass(Variables)