Back to index

plone3  3.1.7
workflow.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """DCWorkflowDefinition browser views.
00014 
00015 $Id: workflow.py 73035 2007-03-07 16:41:03Z jens $
00016 """
00017 
00018 from xml.dom.minidom import parseString
00019 
00020 from zope.component import queryMultiAdapter
00021 from zope.component import queryUtility
00022 
00023 from Products.GenericSetup.browser.utils import AddWithPresettingsViewBase
00024 from Products.GenericSetup.interfaces import IBody
00025 from Products.GenericSetup.interfaces import ISetupTool
00026 
00027 from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
00028 
00029 
00030 class DCWorkflowDefinitionAddView(AddWithPresettingsViewBase):
00031 
00032     """Add view for DCWorkflowDefinition.
00033     """
00034 
00035     klass = DCWorkflowDefinition
00036 
00037     description = u'Add a web-configurable workflow.'
00038 
00039     def getProfileInfos(self):
00040         profiles = []
00041         stool = queryUtility(ISetupTool)
00042         if stool:
00043             for info in stool.listContextInfos():
00044                 obj_ids = []
00045                 context = stool._getImportContext(info['id'])
00046                 file_ids = context.listDirectory('workflows')
00047                 for file_id in file_ids or ():
00048                     filename = 'workflows/%s/definition.xml' % file_id
00049                     body = context.readDataFile(filename)
00050                     if body is None:
00051                         continue
00052                     root = parseString(body).documentElement
00053                     obj_id = root.getAttribute('workflow_id')
00054                     obj_ids.append(obj_id)
00055                 if not obj_ids:
00056                     continue
00057                 obj_ids.sort()
00058                 profiles.append({'id': info['id'],
00059                                  'title': info['title'],
00060                                  'obj_ids': tuple(obj_ids)})
00061         return tuple(profiles)
00062 
00063     def _initSettings(self, obj, profile_id, obj_path):
00064         stool = queryUtility(ISetupTool)
00065         if stool is None:
00066             return
00067 
00068         context = stool._getImportContext(profile_id)
00069         file_ids = context.listDirectory('workflows')
00070         for file_id in file_ids or ():
00071             filename = 'workflows/%s/definition.xml' % file_id
00072             body = context.readDataFile(filename)
00073             if body is None:
00074                 continue
00075 
00076             root = parseString(body).documentElement
00077             if not root.getAttribute('workflow_id') == obj_path[0]:
00078                 continue
00079 
00080             importer = queryMultiAdapter((obj, context), IBody)
00081             if importer is None:
00082                 continue
00083 
00084             importer.body = body
00085             return