From f4cf9bf5427a377141a610f2dfdaefe8ed94fae7 Mon Sep 17 00:00:00 2001
From: Leonardo Rochael Almeida <leonardo@nexedi.com>
Date: Thu, 28 Jan 2010 21:16:16 +0000
Subject: [PATCH] Get rid of pointless "check before you leap" uses of
 portal_workflow.getActionsFor(), which, by the way, has disappeared from CMF
 2

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32080 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_core/Base_workflowStatusModify.xml       | 15 ++++++---------
 .../portal_skins/erp5_core/Folder_delete.xml      | 10 ++++++++--
 product/ERP5/bootstrap/erp5_core/bt/revision      |  2 +-
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_workflowStatusModify.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_workflowStatusModify.xml
index 319301bad7..e5406cbf04 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_workflowStatusModify.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_workflowStatusModify.xml
@@ -54,19 +54,18 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
+from Products.CMFCore.WorkflowCore import WorkflowException\n
 \n
 o = context.getObject()\n
 \n
-action_list = context.portal_workflow.getActionsFor(o)\n
-action_list = filter(lambda x:x.has_key(\'id\'), action_list )\n
-action_id_list = map(lambda x:x[\'id\'], action_list)\n
-\n
-if workflow_action in action_id_list:\n
+if 1: # keep indentation\n
   try : \n
     context.portal_workflow.doActionFor( o,\n
      workflow_action,\n
      comment=comment,\n
      **kw)\n
+  except WorkflowException:\n
+    pass\n
   except ValidationFailed, message:\n
     if getattr(message, \'msg\', None) and same_type(message.msg, []):\n
       message = \'. \'.join(\'%s\' % x for x in message.msg)\n
@@ -116,13 +115,11 @@ if workflow_action in action_id_list:\n
                             <string>kw</string>
                             <string>Products.DCWorkflow.DCWorkflow</string>
                             <string>ValidationFailed</string>
+                            <string>Products.CMFCore.WorkflowCore</string>
+                            <string>WorkflowException</string>
                             <string>_getattr_</string>
                             <string>context</string>
                             <string>o</string>
-                            <string>action_list</string>
-                            <string>filter</string>
-                            <string>map</string>
-                            <string>action_id_list</string>
                             <string>_apply_</string>
                             <string>message</string>
                             <string>getattr</string>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_delete.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_delete.xml
index da6f323e2f..7b7e74c5b4 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_delete.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Folder_delete.xml
@@ -56,6 +56,8 @@
             <value> <string encoding="cdata"><![CDATA[
 
 from ZODB.POSException import ConflictError\n
+from Products.CMFCore.WorkflowCore import WorkflowException\n
+\n
 portal = context.getPortalObject()\n
 Base_translateString = portal.Base_translateString\n
 \n
@@ -146,11 +148,13 @@ elif uids is not None:\n
       object_ids = [x.getId() for x in object_to_remove_list]\n
       comment = Base_translateString(\'Deleted objects: ${object_ids}\',\n
                                      mapping={\'object_ids\': object_ids})\n
-      if \'edit_action\' in [x.get(\'id\', \'\') for x in\n
-                           portal.portal_workflow.getActionsFor(context)]:\n
+      try:\n
         # record object deletion in workflow history\n
         portal.portal_workflow.doActionFor(context, \'edit_action\',\n
                                            comment=comment)\n
+      except WorkflowException:\n
+        # no \'edit_action\' transition for this container\n
+        pass\n
 \n
       message = Base_translateString("Deleted.")\n
 \n
@@ -238,6 +242,8 @@ return REQUEST.RESPONSE.redirect("%s%s" % (ret_url, qs))\n
                             <string>md5_object_uid_list</string>
                             <string>ZODB.POSException</string>
                             <string>ConflictError</string>
+                            <string>Products.CMFCore.WorkflowCore</string>
+                            <string>WorkflowException</string>
                             <string>_getattr_</string>
                             <string>context</string>
                             <string>portal</string>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index 28e1597ccc..6017717271 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-1447
\ No newline at end of file
+1451
\ No newline at end of file
-- 
2.30.9