[CMF-checkins] SVN: CMF/trunk/ - converted WorkflowException messages to i18n messages

Yvo Schubbe y.2006_ at wcm-solutions.de
Tue May 16 15:41:00 EDT 2006


Log message for revision 68156:
  - converted WorkflowException messages to i18n messages
  - catch WorkflowExceptions on skin level

Changed:
  U   CMF/trunk/CMFCore/WorkflowTool.py
  U   CMF/trunk/CMFDefault/exceptions.py
  U   CMF/trunk/CMFDefault/locales/cmf_default.pot
  U   CMF/trunk/CMFDefault/skins/zpt_content/content_status_modify.py
  U   CMF/trunk/DCWorkflow/DCWorkflow.py
  U   CMF/trunk/DCWorkflow/utils.py

-=-
Modified: CMF/trunk/CMFCore/WorkflowTool.py
===================================================================
--- CMF/trunk/CMFCore/WorkflowTool.py	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/CMFCore/WorkflowTool.py	2006-05-16 19:40:59 UTC (rev 68156)
@@ -33,6 +33,7 @@
 from permissions import ManagePortal
 from utils import _dtmldir
 from utils import getToolByName
+from utils import Message as _
 from utils import UniqueObject
 from WorkflowCore import ObjectDeleted
 from WorkflowCore import ObjectMoved
@@ -230,20 +231,21 @@
             wfs = ()
         if wf_id is None:
             if not wfs:
-                raise WorkflowException('No workflows found.')
+                raise WorkflowException(_(u'No workflows found.'))
             found = 0
             for wf in wfs:
                 if wf.isActionSupported(ob, action, **kw):
                     found = 1
                     break
             if not found:
-                raise WorkflowException(
-                    'No workflow provides the "%s" action.' % action)
+                msg = _(u"No workflow provides the '${action_id}' action.",
+                        mapping={'action_id': action})
+                raise WorkflowException(msg)
         else:
             wf = self.getWorkflowById(wf_id)
             if wf is None:
                 raise WorkflowException(
-                    'Requested workflow definition not found.')
+                    _(u'Requested workflow definition not found.'))
         return self._invokeWithNotification(
             wfs, ob, action, wf.doActionFor, (ob, action) + args, kw)
 
@@ -262,7 +264,7 @@
             wfs = self.getWorkflowsFor(ob)
             if wfs is None:
                 if default is _marker:
-                    raise WorkflowException('No workflows found.')
+                    raise WorkflowException(_(u'No workflows found.'))
                 else:
                     return default
             found = 0
@@ -272,8 +274,9 @@
                     break
             if not found:
                 if default is _marker:
-                    raise WorkflowException(
-                        'No workflow provides "%s" information.' % name)
+                    msg = _(u"No workflow provides '${name}' information.",
+                            mapping={'name': name})
+                    raise WorkflowException(msg)
                 else:
                     return default
         else:
@@ -281,12 +284,13 @@
             if wf is None:
                 if default is _marker:
                     raise WorkflowException(
-                        'Requested workflow definition not found.')
+                        _(u'Requested workflow definition not found.'))
                 else:
                     return default
         res = wf.getInfoFor(ob, name, default, *args, **kw)
         if res is _marker:
-            raise WorkflowException('Could not get info: %s' % name)
+            msg = _(u'Could not get info: ${name}', mapping={'name': name})
+            raise WorkflowException(msg)
         return res
 
     security.declarePrivate('notifyCreated')

Modified: CMF/trunk/CMFDefault/exceptions.py
===================================================================
--- CMF/trunk/CMFDefault/exceptions.py	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/CMFDefault/exceptions.py	2006-05-16 19:40:59 UTC (rev 68156)
@@ -30,6 +30,9 @@
 security.declarePublic('ResourceLockedError')
 from Products.CMFCore.exceptions import ResourceLockedError
 
+security.declarePublic('WorkflowException')
+from Products.CMFCore.WorkflowCore import WorkflowException
+
 security.declarePublic('zExceptions_Unauthorized')
 from Products.CMFCore.exceptions import zExceptions_Unauthorized
 

Modified: CMF/trunk/CMFDefault/locales/cmf_default.pot
===================================================================
--- CMF/trunk/CMFDefault/locales/cmf_default.pot	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/CMFDefault/locales/cmf_default.pot	2006-05-16 19:40:59 UTC (rev 68156)
@@ -24,6 +24,31 @@
 msgid "The login name you selected is already in use or is not valid. Please choose another."
 msgstr ""
 
+#: CMFCore/WorkflowTool.py:234
+#: CMFCore/WorkflowTool.py:267
+msgid "No workflows found."
+msgstr ""
+
+#: CMFCore/WorkflowTool.py:241
+# Default: ""
+msgid "No workflow provides the '${action_id}' action."
+msgstr ""
+
+#: CMFCore/WorkflowTool.py:248
+#: CMFCore/WorkflowTool.py:287
+msgid "Requested workflow definition not found."
+msgstr ""
+
+#: CMFCore/WorkflowTool.py:277
+# Default: ""
+msgid "No workflow provides '${name}' information."
+msgstr ""
+
+#: CMFCore/WorkflowTool.py:292
+# Default: ""
+msgid "Could not get info: ${name}"
+msgstr ""
+
 #: CMFDefault/Document.py:108
 msgid "Intervening changes from elsewhere detected. Please refetch the document and reapply your changes. (You may be able to recover your version using the browser 'back' button, but will have to apply them to a freshly fetched copy.)"
 msgstr ""
@@ -934,7 +959,7 @@
 msgid "Content Item status history"
 msgstr ""
 
-#: CMFDefault/skins/zpt_content/content_status_modify.py:11
+#: CMFDefault/skins/zpt_content/content_status_modify.py:12
 msgid "Status changed."
 msgstr ""
 
@@ -2036,17 +2061,17 @@
 msgid "Comments:"
 msgstr ""
 
-#: CMFDefault/utils.py:325
+#: CMFDefault/utils.py:324
 # Default: ""
 msgid "JavaScript event '${attribute}' not allowed."
 msgstr ""
 
-#: CMFDefault/utils.py:330
+#: CMFDefault/utils.py:329
 # Default: ""
 msgid "JavaScript URI '${value}' not allowed."
 msgstr ""
 
-#: CMFDefault/utils.py:343
+#: CMFDefault/utils.py:342
 # Default: ""
 msgid "Dynamic tag '${tag}' not allowed."
 msgstr ""
@@ -2079,6 +2104,20 @@
 msgid "Query Parameters:"
 msgstr ""
 
+#: DCWorkflow/DCWorkflow.py:279
+msgid "Object is in an undefined state."
+msgstr ""
+
+#: DCWorkflow/DCWorkflow.py:284
+# Default: ""
+msgid "Transition '${action_id}' is not triggered by a user action."
+msgstr ""
+
+#: DCWorkflow/DCWorkflow.py:467
+# Default: ""
+msgid "Destination state undefined: ${state_id}"
+msgstr ""
+
 msgid "Found ${count} ${type}."
 msgstr ""
 

Modified: CMF/trunk/CMFDefault/skins/zpt_content/content_status_modify.py
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_content/content_status_modify.py	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/CMFDefault/skins/zpt_content/content_status_modify.py	2006-05-16 19:40:59 UTC (rev 68156)
@@ -2,11 +2,15 @@
 ##title=Modify the status of a content object
 ##
 from Products.CMFCore.utils import getToolByName
+from Products.CMFDefault.exceptions import WorkflowException
 from Products.CMFDefault.utils import Message as _
 
 wtool = getToolByName(script, 'portal_workflow')
 
-wtool.doActionFor(context, workflow_action, comment=comment)
-
-context.setStatus(True, _(u'Status changed.'))
-context.setRedirect(context, 'object/view')
+try:
+    wtool.doActionFor(context, workflow_action, comment=comment)
+    context.setStatus(True, _(u'Status changed.'))
+    context.setRedirect(context, 'object/view')
+except WorkflowException, errmsg:
+    context.setStatus(False, errmsg)
+    context.setRedirect(context, 'object/edit')

Modified: CMF/trunk/DCWorkflow/DCWorkflow.py
===================================================================
--- CMF/trunk/DCWorkflow/DCWorkflow.py	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/DCWorkflow/DCWorkflow.py	2006-05-16 19:40:59 UTC (rev 68156)
@@ -39,6 +39,7 @@
 # DCWorkflow
 from interfaces import IDCWorkflowDefinition
 from permissions import ManagePortal
+from utils import Message as _
 from utils import modifyRolesForPermission
 from utils import modifyRolesForGroup
 from WorkflowUIMixin import WorkflowUIMixin
@@ -275,13 +276,14 @@
         kw['comment'] = comment
         sdef = self._getWorkflowStateOf(ob)
         if sdef is None:
-            raise WorkflowException, 'Object is in an undefined state'
+            raise WorkflowException(_(u'Object is in an undefined state.'))
         if action not in sdef.transitions:
             raise Unauthorized(action)
         tdef = self.transitions.get(action, None)
         if tdef is None or tdef.trigger_type != TRIGGER_USER_ACTION:
-            raise WorkflowException, (
-                'Transition %s is not triggered by a user action' % action)
+            msg = _(u"Transition '${action_id}' is not triggered by a user "
+                    u"action.", mapping={'action_id': action})
+            raise WorkflowException(msg)
         if not self._checkTransitionGuard(tdef, ob, **kw):
             raise Unauthorized(action)
         self._changeStateOf(ob, tdef, kw)
@@ -462,8 +464,9 @@
             former_status = self._getStatusOf(ob)
         new_sdef = self.states.get(new_state, None)
         if new_sdef is None:
-            raise WorkflowException, (
-                'Destination state undefined: ' + new_state)
+            msg = _(u'Destination state undefined: ${state_id}',
+                    mapping={'state_id': new_state})
+            raise WorkflowException(msg)
 
         # Execute the "before" script.
         if tdef is not None and tdef.script_name:

Modified: CMF/trunk/DCWorkflow/utils.py
===================================================================
--- CMF/trunk/DCWorkflow/utils.py	2006-05-16 19:01:53 UTC (rev 68155)
+++ CMF/trunk/DCWorkflow/utils.py	2006-05-16 19:40:59 UTC (rev 68156)
@@ -17,10 +17,14 @@
 
 import os
 
+from AccessControl import ModuleSecurityInfo
 from AccessControl.Permission import Permission
 from AccessControl.Role import gather_permissions
 from App.Common import package_home
+from zope.i18nmessageid import MessageFactory
 
+security = ModuleSecurityInfo('Products.DCWorkflow.utils')
+
 _dtmldir = os.path.join( package_home( globals() ), 'dtml' )
 _xmldir = os.path.join( package_home( globals() ), 'xml' )
 
@@ -96,3 +100,6 @@
             local_roles[group] = roles
         ob.__ac_local_roles__ = local_roles
     return changed
+
+security.declarePublic('Message')
+Message = _ = MessageFactory('cmf_default')



More information about the CMF-checkins mailing list