[Zope-CMF] [DCWorkflow] patch to add condition for transition action
Encolpe DEGOUTE
edegoute at nuxeo.com
Fri Dec 5 05:36:02 EST 2003
Hi,
I just need it then I make it.
It adds the possibility to use a condition to display the transition
action.
I start from DCWorkflow embedded in CMF 1.4.2 release.
A patch for CPS3 is also available on demand.
diff -ur DCWorkflow/DCWorkflow.py /home/zopes/dev/Products/DCWorkflow/DCWorkflow.py
--- DCWorkflow/DCWorkflow.py 2003-03-26 17:51:49.000000000 +0100
+++ /home/zopes/dev/Products/DCWorkflow/DCWorkflow.py 2003-12-05 11:10:18.000000000 +0100
@@ -43,7 +43,7 @@
from WorkflowUIMixin import WorkflowUIMixin
from Transitions import TRIGGER_AUTOMATIC, TRIGGER_USER_ACTION, \
TRIGGER_WORKFLOW_METHOD
-from Expression import StateChangeInfo, createExprContext
+from Expression import Expression, StateChangeInfo, createExprContext
Unauthorized = 'Unauthorized'
@@ -175,6 +175,7 @@
Returns the actions to be displayed to the user.
'''
ob = info.content
+ status = self._getStatusOf(ob)
sdef = self._getWorkflowStateOf(ob)
if sdef is None:
return None
@@ -184,13 +185,30 @@
if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION:
if tdef.actbox_name:
if self._checkTransitionGuard(tdef, ob):
- res.append((tid, {
- 'id': tid,
- 'name': tdef.actbox_name % info,
- 'url': tdef.actbox_url % info,
- 'permissions': (), # Predetermined.
- 'category': tdef.actbox_category,
- 'transition': tdef}))
+ actbox_condition = tdef.actbox_condition
+ if (actbox_condition and
+ type(actbox_condition) == type('')):
+
+ ec = createExprContext(StateChangeInfo(ob, self, status))
+ actbox_condition = Expression(actbox_condition)
+ if actbox_condition(ec):
+ res.append((tid, {
+ 'id': tid,
+ 'name': tdef.actbox_name % info,
+ 'url': tdef.actbox_url % info,
+ 'condition': actbox_condition,
+ 'permissions': (), # Predetermined.
+ 'category': tdef.actbox_category,
+ 'transition': tdef}))
+ else:
+ res.append((tid, {
+ 'id': tid,
+ 'name': tdef.actbox_name % info,
+ 'url': tdef.actbox_url % info,
+ 'condition': actbox_condition,
+ 'permissions': (), # Predetermined.
+ 'category': tdef.actbox_category,
+ 'transition': tdef}))
res.sort()
return map((lambda (id, val): val), res)
@@ -205,6 +223,8 @@
if not self.worklists:
return None # Optimization
sm = getSecurityManager()
+ ob = info.content
+ status = self._getStatusOf(ob)
portal = self._getPortalRoot()
res = []
fmt_data = None
@@ -230,10 +250,30 @@
fmt_data._push(info)
searchres_len = lambda searchres=searchres: len(searchres)
fmt_data._push({'count': searchres_len})
- res.append((id, {'name': qdef.actbox_name % fmt_data,
- 'url': qdef.actbox_url % fmt_data,
- 'permissions': (), # Predetermined.
- 'category': qdef.actbox_category}))
+ actbox_condition = tdef.actbox_condition
+ if (actbox_condition and
+ type(actbox_condition) == type('')):
+
+ ec = createExprContext(StateChangeInfo(ob, self, status))
+ actbox_condition = Expression(actbox_condition)
+ if actbox_condition(ec):
+ res.append((id, {
+ 'id': id,
+ 'name': qdef.actbox_name % info,
+ 'url': qdef.actbox_url % info,
+ 'condition': actbox_condition,
+ 'permissions': (), # Predetermined.
+ 'category': qdef.actbox_category,
+ 'transition': qdef}))
+ else:
+ res.append((id, {
+ 'id': id,
+ 'name': qdef.actbox_name % info,
+ 'url': qdef.actbox_url % info,
+ 'condition': actbox_condition,
+ 'permissions': (), # Predetermined.
+ 'category': qdef.actbox_category,
+ 'transition': qdef}))
fmt_data._pop()
res.sort()
return map((lambda (id, val): val), res)
Seulement dans /home/zopes/dev/Products/DCWorkflow: DCWorkflow.pyc
diff -ur DCWorkflow/dtml/transition_properties.dtml /home/zopes/dev/Products/DCWorkflow/dtml/transition_properties.dtml
--- DCWorkflow/dtml/transition_properties.dtml 2003-02-02 01:31:54.000000000 +0100
+++ /home/zopes/dev/Products/DCWorkflow/dtml/transition_properties.dtml 2003-12-04 19:20:01.000000000 +0100
@@ -127,6 +127,14 @@
value="&dtml-actbox_category;" />
</td>
</tr>
+ <tr>
+ <th align="left">Condition</th>
+ <td>
+ <input type="text" name="actbox_condition"
+ value="&dtml-actbox_condition;" />
+ </td>
+ </tr>
+ </table>
</table>
</td>
</tr>
diff -ur DCWorkflow/dtml/worklist_properties.dtml /home/zopes/dev/Products/DCWorkflow/dtml/worklist_properties.dtml
--- DCWorkflow/dtml/worklist_properties.dtml 2002-07-04 15:30:42.000000000 +0200
+++ /home/zopes/dev/Products/DCWorkflow/dtml/worklist_properties.dtml 2003-12-04 19:19:48.000000000 +0100
@@ -64,6 +64,14 @@
value="&dtml-actbox_category;" />
</td>
</tr>
+ <tr>
+ <th align="left">Condition</th>
+ <td>
+ <input type="text" name="actbox_condition"
+ value="&dtml-actbox_condition;" />
+ </td>
+ </tr>
+ </table>
</table>
</td>
</tr>
diff -ur DCWorkflow/Transitions.py /home/zopes/dev/Products/DCWorkflow/Transitions.py
--- DCWorkflow/Transitions.py 2002-11-07 12:25:26.000000000 +0100
+++ /home/zopes/dev/Products/DCWorkflow/Transitions.py 2003-12-05 11:13:07.000000000 +0100
@@ -49,6 +49,7 @@
actbox_name = ''
actbox_url = ''
actbox_category = 'workflow'
+ actbox_condition = ''
var_exprs = None # A mapping.
script_name = None # Executed before transition
after_script_name = None # Executed after transition
@@ -113,6 +114,7 @@
after_script_name='',
actbox_name='', actbox_url='',
actbox_category='workflow',
+ actbox_condition='',
props=None, REQUEST=None, description=''):
'''
'''
@@ -130,6 +132,10 @@
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category)
+ ## XXX We can't store object in DTML File properties
+ #if actbox_condition and type(actbox_condition) == type(''):
+ # actbox_condition = Expression(actbox_condition)
+ self.actbox_condition = actbox_condition
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
Seulement dans /home/zopes/dev/Products/DCWorkflow: Transitions.pyc
diff -ur DCWorkflow/version.txt /home/zopes/dev/Products/DCWorkflow/version.txt
--- DCWorkflow/version.txt 2003-10-27 18:30:11.000000000 +0100
+++ /home/zopes/dev/Products/DCWorkflow/version.txt 2003-09-29 08:13:45.000000000 +0200
@@ -1 +1 @@
-CMF-1.4.2
+CMF-1.4.1
diff -ur DCWorkflow/Worklists.py /home/zopes/dev/Products/DCWorkflow/Worklists.py
--- DCWorkflow/Worklists.py 2002-10-25 17:49:47.000000000 +0200
+++ /home/zopes/dev/Products/DCWorkflow/Worklists.py 2003-12-05 07:03:21.000000000 +0100
@@ -40,6 +40,7 @@
actbox_name = ''
actbox_url = ''
actbox_category = 'global'
+ actbox_condition = ''
guard = None
manage_options = (
@@ -106,7 +107,7 @@
def setProperties(self, description,
actbox_name='', actbox_url='', actbox_category='global',
- props=None, REQUEST=None):
+ actbox_condition='', props=None, REQUEST=None):
'''
'''
if props is None:
@@ -127,6 +128,10 @@
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category)
+ ## XXX We can't store object in DTML File properties
+ #if actbox_condition and type(actbox_condition) == type (''):
+ # actbox_condition = Expression(actbox_condition)
+ self.actbox_condition = actbox_condition
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
--
Encolpe DEGOUTE, Ingenieur Logiciel, Nuxeo SARL: Zope Service Provider.
Mail: edegoute at nuxeo.com - Tel: +33 (0)1 40 33 79 18
Nuxeo Collaborative Portal Server: http://www.nuxeo.com/cps
Gestion de contenu web / portail collaboratif / groupware / open source
More information about the Zope-CMF
mailing list