[CMF-checkins] SVN: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py - apply selected presettings to new object

Yvo Schubbe y.2005- at wcm-solutions.de
Tue Nov 22 11:58:26 EST 2005


Log message for revision 40325:
  - apply selected presettings to new object
  

Changed:
  U   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py

-=-
Modified: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py	2005-11-22 16:43:41 UTC (rev 40324)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py	2005-11-22 16:58:26 UTC (rev 40325)
@@ -17,7 +17,10 @@
 
 from xml.dom.minidom import parseString
 
+from zope.app import zapi
+
 from Products.CMFCore.utils import getToolByName
+from Products.GenericSetup.interfaces import IBody
 
 from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
 
@@ -39,7 +42,10 @@
                 profile_id, obj_id = settings_id.split('/')
                 if not add_input_name:
                     self.request.set('add_input_name', obj_id)
-            obj = DCWorkflowDefinition('temp')
+                obj = DCWorkflowDefinition('temp')
+                self._init(obj, profile_id, obj_id)
+            else:
+                obj = DCWorkflowDefinition('temp')
             self.context.add(obj)
             self.request.response.redirect(self.context.nextURL())
             return ''
@@ -68,3 +74,27 @@
                                  'title': info['title'],
                                  'obj_ids': tuple(obj_ids)})
         return tuple(profiles)
+
+    def _init(self, obj, profile_id, obj_id):
+        stool = getToolByName(self, 'portal_setup', None)
+        if stool is None:
+            return
+
+        context = stool._getImportContext(profile_id)
+        file_ids = context.listDirectory('workflows')
+        for file_id in file_ids or ():
+            filename = 'workflows/%s/definition.xml' % file_id
+            body = context.readDataFile(filename)
+            if body is None:
+                continue
+
+            root = parseString(body).documentElement
+            if not root.getAttribute('workflow_id') == obj_id:
+                continue
+
+            importer = zapi.queryMultiAdapter((obj, context), IBody)
+            if importer is None:
+                continue
+
+            importer.body = body
+            return



More information about the CMF-checkins mailing list