vendor/CMF/1.6.1/DCWorkflow

view Default.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 """ Programmatically creates a workflow.
15 $Id: Default.py 36457 2004-08-12 15:07:44Z jens $
16 """
18 from Products.CMFCore.WorkflowTool import addWorkflowFactory
20 from DCWorkflow import DCWorkflowDefinition
21 from permissions import AccessContentsInformation
22 from permissions import ModifyPortalContent
23 from permissions import RequestReview
24 from permissions import ReviewPortalContent
25 from permissions import View
27 p_access = AccessContentsInformation
28 p_modify = ModifyPortalContent
29 p_request = RequestReview
30 p_review = ReviewPortalContent
31 p_view = View
33 r_anon = 'Anonymous'
34 r_manager = 'Manager'
35 r_reviewer = 'Reviewer'
36 r_owner = 'Owner'
37 r_member = 'Member'
41 def setupDefaultWorkflowRev2(wf):
42 '''
43 Sets up a DCWorkflow with the addition of a visible state,
44 the show and hide transitions, and corresponding changes.
45 wf is a DCWorkflow instance.
46 '''
47 wf.setProperties(title='CMF default workflow [Revision 2]')
49 for s in ('private', 'visible', 'pending', 'published'):
50 wf.states.addState(s)
51 for t in ('publish', 'reject', 'retract', 'submit', 'hide', 'show'):
52 wf.transitions.addTransition(t)
53 for v in ('action', 'actor', 'comments', 'review_history', 'time'):
54 wf.variables.addVariable(v)
55 for l in ('reviewer_queue',):
56 wf.worklists.addWorklist(l)
57 for p in (p_access, p_modify, p_view):
58 wf.addManagedPermission(p)
60 wf.states.setInitialState('visible')
62 sdef = wf.states['private']
63 sdef.setProperties(
64 title='Visible and editable only by owner',
65 transitions=('show',))
66 sdef.setPermission(p_access, 0, (r_manager, r_owner))
67 sdef.setPermission(p_view, 0, (r_manager, r_owner))
68 sdef.setPermission(p_modify, 0, (r_manager, r_owner))
70 sdef = wf.states['pending']
71 sdef.setProperties(
72 title='Waiting for reviewer',
73 transitions=('hide', 'publish', 'reject', 'retract',))
74 sdef.setPermission(p_access, 1, (r_manager, r_owner, r_reviewer))
75 sdef.setPermission(p_view, 1, (r_manager, r_owner, r_reviewer))
76 sdef.setPermission(p_modify, 0, (r_manager, r_reviewer))
78 sdef = wf.states['published']
79 sdef.setProperties(
80 title='Public',
81 transitions=('reject', 'retract',))
82 sdef.setPermission(p_access, 1, (r_anon, r_manager))
83 sdef.setPermission(p_view, 1, (r_anon, r_manager))
84 sdef.setPermission(p_modify, 0, (r_manager,))
86 sdef = wf.states['visible']
87 sdef.setProperties(
88 title='Visible but not published',
89 transitions=('hide', 'publish', 'submit',))
90 sdef.setPermission(p_access, 1, (r_anon, r_manager, r_reviewer))
91 sdef.setPermission(p_view, 1, (r_anon, r_manager, r_reviewer))
92 sdef.setPermission(p_modify, 0, (r_manager, r_owner))
94 tdef = wf.transitions['hide']
95 tdef.setProperties(
96 title='Member makes content private',
97 new_state_id='private',
98 actbox_name='Make private',
99 actbox_url='%(content_url)s/content_hide_form',
100 props={'guard_roles':r_owner})
102 tdef = wf.transitions['publish']
103 tdef.setProperties(
104 title='Reviewer publishes content',
105 new_state_id='published',
106 actbox_name='Publish',
107 actbox_url='%(content_url)s/content_publish_form',
108 props={'guard_permissions':p_review})
110 tdef = wf.transitions['reject']
111 tdef.setProperties(
112 title='Reviewer rejects submission',
113 new_state_id='visible',
114 actbox_name='Reject',
115 actbox_url='%(content_url)s/content_reject_form',
116 props={'guard_permissions':p_review})
118 tdef = wf.transitions['retract']
119 tdef.setProperties(
120 title='Member retracts submission',
121 new_state_id='visible',
122 actbox_name='Retract',
123 actbox_url='%(content_url)s/content_retract_form',
124 props={'guard_permissions':p_request})
126 tdef = wf.transitions['show']
127 tdef.setProperties(
128 title='Member makes content visible',
129 new_state_id='visible',
130 actbox_name='Make visible',
131 actbox_url='%(content_url)s/content_show_form',
132 props={'guard_roles':r_owner})
134 tdef = wf.transitions['submit']
135 tdef.setProperties(
136 title='Member requests publishing',
137 new_state_id='pending',
138 actbox_name='Submit',
139 actbox_url='%(content_url)s/content_submit_form',
140 props={'guard_permissions':p_request})
142 wf.variables.setStateVar('review_state')
144 vdef = wf.variables['action']
145 vdef.setProperties(description='The last transition',
146 default_expr='transition/getId|nothing',
147 for_status=1, update_always=1)
149 vdef = wf.variables['actor']
150 vdef.setProperties(description='The ID of the user who performed '
151 'the last transition',
152 default_expr='user/getId',
153 for_status=1, update_always=1)
155 vdef = wf.variables['comments']
156 vdef.setProperties(description='Comments about the last transition',
157 default_expr="python:state_change.kwargs.get('comment', '')",
158 for_status=1, update_always=1)
160 vdef = wf.variables['review_history']
161 vdef.setProperties(description='Provides access to workflow history',
162 default_expr="state_change/getHistory",
163 props={'guard_permissions':
164 p_request + ';' + p_review})
166 vdef = wf.variables['time']
167 vdef.setProperties(description='Time of the last transition',
168 default_expr="state_change/getDateTime",
169 for_status=1, update_always=1)
171 ldef = wf.worklists['reviewer_queue']
172 ldef.setProperties(description='Reviewer tasks',
173 actbox_name='Pending (%(count)d)',
174 actbox_url='%(portal_url)s/search?review_state=pending',
175 props={'var_match_review_state':'pending',
176 'guard_permissions':p_review})
179 def createDefaultWorkflowRev2(id):
180 '''
181 '''
182 ob = DCWorkflowDefinition(id)
183 setupDefaultWorkflowRev2(ob)
184 return ob
186 addWorkflowFactory(createDefaultWorkflowRev2, id='default_workflow',
187 title='Web-configurable workflow [Revision 2]')
197 def setupDefaultWorkflowClassic(wf):
198 '''
199 Sets up a DCWorkflow as close as possible to the old DefaultWorkflow,
200 with only the private, pending, and published states.
201 wf is a DCWorkflow instance.
202 '''
203 wf.setProperties(title='CMF default workflow [Classic]')
205 for s in ('private', 'pending', 'published'):
206 wf.states.addState(s)
207 for t in ('publish', 'reject', 'retract', 'submit'):
208 wf.transitions.addTransition(t)
209 for v in ('action', 'actor', 'comments', 'review_history', 'time'):
210 wf.variables.addVariable(v)
211 for l in ('reviewer_queue',):
212 wf.worklists.addWorklist(l)
213 for p in (p_access, p_modify, p_view):
214 wf.addManagedPermission(p)
216 wf.states.setInitialState('private')
218 sdef = wf.states['private']
219 sdef.setProperties(
220 title='Non-visible and editable only by owner',
221 transitions=('submit', 'publish',))
222 sdef.setPermission(p_access, 0, (r_manager, r_owner))
223 sdef.setPermission(p_view, 0, (r_manager, r_owner))
224 sdef.setPermission(p_modify, 0, (r_manager, r_owner))
226 sdef = wf.states['pending']
227 sdef.setProperties(
228 title='Waiting for reviewer',
229 transitions=('publish', 'reject', 'retract',))
230 sdef.setPermission(p_access, 0, (r_manager, r_owner, r_reviewer))
231 sdef.setPermission(p_view, 0, (r_manager, r_owner, r_reviewer))
232 sdef.setPermission(p_modify, 0, (r_manager, r_reviewer))
234 sdef = wf.states['published']
235 sdef.setProperties(
236 title='Public',
237 transitions=('reject', 'retract',))
238 sdef.setPermission(p_access, 1, (r_anon, r_manager))
239 sdef.setPermission(p_view, 1, (r_anon, r_manager))
240 sdef.setPermission(p_modify, 0, (r_manager,))
242 tdef = wf.transitions['publish']
243 tdef.setProperties(
244 title='Reviewer publishes content',
245 new_state_id='published',
246 actbox_name='Publish',
247 actbox_url='%(content_url)s/content_publish_form',
248 props={'guard_permissions':p_review})
250 tdef = wf.transitions['reject']
251 tdef.setProperties(
252 title='Reviewer rejects submission',
253 new_state_id='private',
254 actbox_name='Reject',
255 actbox_url='%(content_url)s/content_reject_form',
256 props={'guard_permissions':p_review})
258 tdef = wf.transitions['retract']
259 tdef.setProperties(
260 title='Member retracts submission',
261 new_state_id='private',
262 actbox_name='Retract',
263 actbox_url='%(content_url)s/content_retract_form',
264 props={'guard_permissions':p_request})
266 tdef = wf.transitions['submit']
267 tdef.setProperties(
268 title='Member requests publishing',
269 new_state_id='pending',
270 actbox_name='Submit',
271 actbox_url='%(content_url)s/content_submit_form',
272 props={'guard_permissions':p_request})
274 wf.variables.setStateVar('review_state')
276 vdef = wf.variables['action']
277 vdef.setProperties(description='The last transition',
278 default_expr='transition/getId|nothing',
279 for_status=1, update_always=1)
281 vdef = wf.variables['actor']
282 vdef.setProperties(description='The ID of the user who performed '
283 'the last transition',
284 default_expr='user/getId',
285 for_status=1, update_always=1)
287 vdef = wf.variables['comments']
288 vdef.setProperties(description='Comments about the last transition',
289 default_expr="python:state_change.kwargs.get('comment', '')",
290 for_status=1, update_always=1)
292 vdef = wf.variables['review_history']
293 vdef.setProperties(description='Provides access to workflow history',
294 default_expr="state_change/getHistory",
295 props={'guard_permissions':
296 p_request + ';' + p_review})
298 vdef = wf.variables['time']
299 vdef.setProperties(description='Time of the last transition',
300 default_expr="state_change/getDateTime",
301 for_status=1, update_always=1)
303 ldef = wf.worklists['reviewer_queue']
304 ldef.setProperties(description='Reviewer tasks',
305 actbox_name='Pending (%(count)d)',
306 actbox_url='%(portal_url)s/search?review_state=pending',
307 props={'var_match_review_state':'pending',
308 'guard_permissions':p_review})
312 def createDefaultWorkflowClassic(id):
313 '''
314 '''
315 ob = DCWorkflowDefinition(id)
316 setupDefaultWorkflowClassic(ob)
317 return ob
319 addWorkflowFactory(createDefaultWorkflowClassic, id='default_workflow',
320 title='Web-configurable workflow [Classic]')