From 4e8750fd19d6caeb400e76dc5fcc594dec6d93e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 27 Apr 2007 13:33:49 +0000
Subject: [PATCH] Translating in a workflow script is a mistake. One should
 raise a ValidationFailed with a Message instance so that translations is
 performed when the message is displayed, not when it's stored in the
 database. Also use newer checkConsistency ConsistencyMessage API

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14277 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../scripts/checkConsistency.xml              | 29 +++++++++----------
 product/ERP5/bootstrap/erp5_core/bt/revision  |  2 +-
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/validation_workflow/scripts/checkConsistency.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/validation_workflow/scripts/checkConsistency.xml
index e5cbecf910..2565cddd07 100644
--- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/validation_workflow/scripts/checkConsistency.xml
+++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/validation_workflow/scripts/checkConsistency.xml
@@ -68,22 +68,19 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string encoding="cdata"><![CDATA[
-
-from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
+            <value> <string>from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
+from Products.ERP5Type.Message import Message\n
 object = state_change[\'object\']\n
-N_ = object.Base_translateString\n
 \n
 check_result = object.checkConsistency()\n
 \n
-if len(check_result) > 0:\n
-  check_type    = N_(check_result[0][-1])\n
-  # TODO: use nice url encoding method there instead of replace()\n
-  check_details = check_result[0][-2].replace(\'<\', \'&lt;\').replace(\'>\', \'&gt;\')\n
-  raise ValidationFailed, "%s : %s" % (check_type, check_details)\n
-
-
-]]></string> </value>
+if check_result:\n
+  err = check_result[0]\n
+  if hasattr(err, \'getTranslatedMessage\'):\n
+    raise ValidationFailed, err.getTranslatedMessage()\n
+  # backward compatibility:\n
+  raise ValidationFailed, "%s: %s" % (err[4], err[3])\n
+</string> </value>
         </item>
         <item>
             <key> <string>_code</string> </key>
@@ -134,14 +131,14 @@ if len(check_result) > 0:\n
                             <string>state_change</string>
                             <string>Products.DCWorkflow.DCWorkflow</string>
                             <string>ValidationFailed</string>
+                            <string>Products.ERP5Type.Message</string>
+                            <string>Message</string>
                             <string>_getitem_</string>
                             <string>object</string>
                             <string>_getattr_</string>
-                            <string>N_</string>
                             <string>check_result</string>
-                            <string>len</string>
-                            <string>check_type</string>
-                            <string>check_details</string>
+                            <string>err</string>
+                            <string>hasattr</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index 272a4581e9..059361f246 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-316
\ No newline at end of file
+317
\ No newline at end of file
-- 
2.30.9