[CMF-checkins] SVN: CMF/branches/yuppie-workflow_setup/ - removed _workflow_factories registry and related methods

Yvo Schubbe y.2005- at wcm-solutions.de
Mon Nov 21 13:57:43 EST 2005


Log message for revision 40304:
  - removed _workflow_factories registry and related methods
  - workflows are now registered the same way as type infos in TypesTool and actions in ActionsTool
  - registered DCWorkflowDefinition the new way
  - added add view for DCWorkflowDefinition (TODO: apply selected presettings to new object)
  - fixed most tests (TODO: fix workflow setup tests)

Changed:
  U   CMF/branches/yuppie-workflow_setup/CMFCore/WorkflowTool.py
  U   CMF/branches/yuppie-workflow_setup/CMFCore/browser/configure.zcml
  U   CMF/branches/yuppie-workflow_setup/CMFCore/tests/test_WorkflowTool.py
  U   CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DefaultWorkflow.py
  U   CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DiscussionReply.py
  U   CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Image.py
  U   CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Portal.py
  U   CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_join.py
  U   CMF/branches/yuppie-workflow_setup/CMFTopic/tests/test_DateC.py
  U   CMF/branches/yuppie-workflow_setup/DCWorkflow/DCWorkflow.py
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/__init__.py
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/addDCWorkflowDefinition.pt
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/configure.zcml
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py
  A   CMF/branches/yuppie-workflow_setup/DCWorkflow/configure.zcml
  U   CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_DCWorkflow.py
  U   CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_guard.py

-=-
Modified: CMF/branches/yuppie-workflow_setup/CMFCore/WorkflowTool.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFCore/WorkflowTool.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFCore/WorkflowTool.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -23,9 +23,11 @@
 from Globals import InitializeClass
 from Globals import PersistentMapping
 from OFS.Folder import Folder
+from OFS.ObjectManager import IFAwareObjectManager
 from zope.interface import implements
 
 from ActionProviderBase import ActionProviderBase
+from interfaces import IWorkflowDefinition
 from interfaces import IWorkflowTool
 from interfaces.portal_workflow import portal_workflow as z2IWorkflowTool
 from permissions import ManagePortal
@@ -40,7 +42,8 @@
 _marker = []  # Create a new marker object.
 
 
-class WorkflowTool(UniqueObject, Folder, ActionProviderBase):
+class WorkflowTool(UniqueObject, IFAwareObjectManager, Folder,
+                   ActionProviderBase):
 
     """ Mediator tool, mapping workflow objects
     """
@@ -50,6 +53,7 @@
 
     id = 'portal_workflow'
     meta_type = 'CMF Workflow Tool'
+    _product_interfaces = (IWorkflowDefinition,)
 
     _chains_by_type = None  # PersistentMapping
     _default_chain = ('default_workflow',)
@@ -69,37 +73,6 @@
     security.declareProtected( ManagePortal, 'manage_overview' )
     manage_overview = DTMLFile( 'explainWorkflowTool', _dtmldir )
 
-    _manage_addWorkflowForm = DTMLFile('addWorkflow', _dtmldir)
-
-    security.declareProtected( ManagePortal, 'manage_addWorkflowForm')
-    def manage_addWorkflowForm(self, REQUEST):
-
-        """ Form for adding workflows.
-        """
-        wft = []
-        for key in _workflow_factories.keys():
-            wft.append(key)
-        wft.sort()
-        return self._manage_addWorkflowForm(REQUEST, workflow_types=wft)
-
-    security.declareProtected( ManagePortal, 'manage_addWorkflow')
-    def manage_addWorkflow(self, workflow_type, id, RESPONSE=None):
-
-        """ Adds a workflow from the registered types.
-        """
-        factory = _workflow_factories[workflow_type]
-        ob = factory(id)
-        self._setObject(id, ob)
-        if RESPONSE is not None:
-            RESPONSE.redirect(self.absolute_url() +
-                              '/manage_main?management_view=Contents')
-
-    def all_meta_types(self):
-        return (
-            {'name': 'Workflow',
-             'action': 'manage_addWorkflowForm',
-             'permission': ManagePortal },)
-
     _manage_selectWorkflows = DTMLFile('selectWorkflows', _dtmldir)
 
     security.declareProtected( ManagePortal, 'manage_selectWorkflows')
@@ -426,8 +399,7 @@
         self._default_chain = tuple(ids)
 
     security.declareProtected( ManagePortal, 'setChainForPortalTypes')
-    def setChainForPortalTypes(self, pt_names, chain):
-
+    def setChainForPortalTypes(self, pt_names, chain, verify=True):
         """ Set a chain for a specific portal type.
         """
         cbt = self._chains_by_type
@@ -437,12 +409,12 @@
         if isinstance(chain, basestring):
             chain = [ wf.strip() for wf in chain.split(',') if wf.strip() ]
 
-        ti = self._listTypeInfo()
-        for t in ti:
-            id = t.getId()
-            if id in pt_names:
-                cbt[id] = tuple(chain)
+        ti_ids = [ t.getId() for t in self._listTypeInfo() ]
 
+        for type_id in pt_names:
+            if verify and not (type_id in ti_ids):
+                continue
+            cbt[type_id] = tuple(chain)
 
     security.declareProtected( ManagePortal, 'updateRoleMappings')
     def updateRoleMappings(self, REQUEST=None):
@@ -464,11 +436,11 @@
 
     security.declarePrivate('getWorkflowById')
     def getWorkflowById(self, wf_id):
-
         """ Retrieve a given workflow.
         """
         wf = getattr(self, wf_id, None)
-        if getattr(wf, '_isAWorkflow', 0):
+        if getattr(wf, '_isAWorkflow', False) or \
+                IWorkflowDefinition.providedBy(wf):
             return wf
         else:
             return None
@@ -651,29 +623,3 @@
             ob.reindexObjectSecurity()
 
 InitializeClass(WorkflowTool)
-
-
-_workflow_factories = {}
-
-def _makeWorkflowFactoryKey(factory, id=None, title=None):
-    # The factory should take one argument, id.
-    if id is None:
-        id = getattr(factory, 'id', '') or getattr(factory, 'meta_type', '')
-    if title is None:
-        title = getattr(factory, 'title', '')
-    key = id
-    if title:
-        key = key + ' (%s)' % title
-    return key
-
-def addWorkflowFactory(factory, id=None, title=None):
-    key = _makeWorkflowFactoryKey( factory, id, title )
-    _workflow_factories[key] = factory
-
-def _removeWorkflowFactory( factory, id=None, title=None ):
-    """ Make teardown in unitcase cleaner. """
-    key = _makeWorkflowFactoryKey( factory, id, title )
-    try:
-        del _workflow_factories[key]
-    except KeyError:
-        pass

Modified: CMF/branches/yuppie-workflow_setup/CMFCore/browser/configure.zcml
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFCore/browser/configure.zcml	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFCore/browser/configure.zcml	2005-11-21 18:57:42 UTC (rev 40304)
@@ -1,9 +1,12 @@
 <configure
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:browser="http://namespaces.zope.org/browser"
-  i18n_domain="cmf"
-  >
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    xmlns:five="http://namespaces.zope.org/five"
+    i18n_domain="cmf"
+    >
 
+  <five:traversable class="Products.CMFCore.WorkflowTool.WorkflowTool"/>
+
   <!-- Set up default menus as action categories. -->
   <browser:menu
     id="object"

Modified: CMF/branches/yuppie-workflow_setup/CMFCore/tests/test_WorkflowTool.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFCore/tests/test_WorkflowTool.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFCore/tests/test_WorkflowTool.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -20,9 +20,7 @@
 
 from OFS.SimpleItem import SimpleItem
 
-from Products.CMFCore.tests.base.testcase import WarningInterceptor
 
-
 class Dummy( SimpleItem ):
 
     def __init__( self, id ):
@@ -131,24 +129,15 @@
         return None
 
 
-class WorkflowToolTests(unittest.TestCase, WarningInterceptor):
+class WorkflowToolTests(unittest.TestCase):
 
-    def setUp( self ):
-        from Products.CMFCore.WorkflowTool import addWorkflowFactory
-        addWorkflowFactory( DummyWorkflow )
-
-    def tearDown( self ):
-        from Products.CMFCore.WorkflowTool import _removeWorkflowFactory
-        _removeWorkflowFactory( DummyWorkflow )
-        self._free_warning_output()
-
     def _makeOne( self, workflow_ids=() ):
         from Products.CMFCore.WorkflowTool import WorkflowTool
 
         tool = WorkflowTool()
 
         for workflow_id in workflow_ids:
-            tool.manage_addWorkflow( DummyWorkflow.meta_type, workflow_id )
+            tool._setObject(workflow_id, DummyWorkflow(workflow_id))
 
         return tool
 

Modified: CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DefaultWorkflow.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DefaultWorkflow.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DefaultWorkflow.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,37 +15,32 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.dummy import DummyUserFolder
 
-from Products.CMFCore.WorkflowTool import addWorkflowFactory
 from Products.CMFCore.WorkflowTool import WorkflowTool
 
-from Products.CMFDefault.MembershipTool import MembershipTool
-from Products.CMFDefault.DefaultWorkflow import DefaultWorkflowDefinition
 
-class DefaultWorkflowDefinitionTests(TestCase):
+class DefaultWorkflowDefinitionTests(unittest.TestCase):
 
     def setUp(self):
-
+        from Products.CMFDefault.DefaultWorkflow \
+                import DefaultWorkflowDefinition
         self.site = DummySite('site')
         self.site._setObject('portal_types', DummyTool())
         self.site._setObject('portal_workflow', WorkflowTool())
-        self.site._setObject('portal_membership', MembershipTool())
+        self.site._setObject('portal_membership', DummyTool())
         self.site._setObject('acl_users', DummyUserFolder())
 
-        addWorkflowFactory(DefaultWorkflowDefinition,
-                           id='default_workflow', title='default_workflow')
+        wftool = self.site.portal_workflow
+        wftool._setObject('wf', DefaultWorkflowDefinition('wf'))
+        wftool.setDefaultChain('wf')
 
-        self._constructDummyWorkflow()
-
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
         from Products.CMFCore.interfaces.portal_workflow \
@@ -63,12 +58,6 @@
 
         verifyClass(IWorkflowDefinition, DefaultWorkflowDefinition)
 
-    def _constructDummyWorkflow(self):
-
-        wftool = self.site.portal_workflow
-        wftool.manage_addWorkflow('default_workflow (default_workflow)', 'wf')
-        wftool.setDefaultChain('wf')
-
     def _getDummyWorkflow(self):
         wftool = self.site.portal_workflow
         return wftool.wf
@@ -92,10 +81,11 @@
 
     # XXX more tests...
 
+
 def test_suite():
-    return TestSuite((
-        makeSuite( DefaultWorkflowDefinitionTests ),
+    return unittest.TestSuite((
+        unittest.makeSuite(DefaultWorkflowDefinitionTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DiscussionReply.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DiscussionReply.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_DiscussionReply.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,10 +15,8 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 import Products
 from AccessControl.SecurityManagement import newSecurityManager
@@ -35,8 +33,10 @@
         PlacelessSetup.setUp(self)
         RequestTest.setUp(self)
         zcml.load_config('meta.zcml', Products.Five)
+        zcml.load_config('permissions.zcml', Products.Five)
         zcml.load_config('configure.zcml', Products.GenericSetup)
         zcml.load_config('configure.zcml', Products.CMFCore)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
         try:
             factory = self.root.manage_addProduct['CMFDefault'].addConfiguredSite
             factory('cmf', 'CMFDefault:default', snapshot=False)
@@ -90,10 +90,10 @@
 
 
 def test_suite():
-    suite = TestSuite()
-    suite.addTest(makeSuite(DiscussionReplyTest))
-    suite.addTest(makeSuite(DiscussionReplyTestMember))
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(DiscussionReplyTest))
+    suite.addTest(unittest.makeSuite(DiscussionReplyTestMember))
     return suite
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Image.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Image.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -100,8 +100,10 @@
         PlacelessSetup.setUp(self)
         RequestTest.setUp(self)
         zcml.load_config('meta.zcml', Products.Five)
+        zcml.load_config('permissions.zcml', Products.Five)
         zcml.load_config('configure.zcml', Products.GenericSetup)
         zcml.load_config('configure.zcml', Products.CMFCore)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
         try:
             newSecurityManager(None, UnrestrictedUser('manager', '', ['Manager'], []))
             factory = self.root.manage_addProduct['CMFDefault'].addConfiguredSite

Modified: CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Portal.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Portal.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_Portal.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,10 +15,8 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 import Products
 from Acquisition import aq_base
@@ -51,8 +49,10 @@
         PlacelessSetup.setUp(self)
         SecurityRequestTest.setUp(self)
         zcml.load_config('meta.zcml', Products.Five)
+        zcml.load_config('permissions.zcml', Products.Five)
         zcml.load_config('configure.zcml', Products.GenericSetup)
         zcml.load_config('configure.zcml', Products.CMFCore)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
 
     def tearDown(self):
         SecurityRequestTest.tearDown(self)
@@ -207,9 +207,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(CMFSiteTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(CMFSiteTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_join.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_join.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFDefault/tests/test_join.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,16 +15,31 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
+import Products
+from Products.Five import zcml
+
+from Products.CMFCore.tests.base.testcase import PlacelessSetup
 from Products.CMFCore.tests.base.testcase import TransactionalTest
 
 
-class MembershipTests( TransactionalTest ):
+class MembershipTests(PlacelessSetup, TransactionalTest):
 
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        TransactionalTest.setUp(self)
+        zcml.load_config('meta.zcml', Products.Five)
+        zcml.load_config('permissions.zcml', Products.Five)
+        zcml.load_config('configure.zcml', Products.GenericSetup)
+        zcml.load_config('configure.zcml', Products.CMFCore)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
+
+    def tearDown(self):
+        TransactionalTest.tearDown(self)
+        PlacelessSetup.tearDown(self)
+
     def _makePortal(self):
         # Create a portal instance suitable for testing
         factory = self.root.manage_addProduct['CMFDefault'].addConfiguredSite
@@ -101,9 +116,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(MembershipTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(MembershipTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/CMFTopic/tests/test_DateC.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/CMFTopic/tests/test_DateC.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/CMFTopic/tests/test_DateC.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,17 +15,17 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 import Products
 from DateTime.DateTime import DateTime
+
 from Products.CMFCore.tests.base.testcase import PlacelessSetup
 from Products.CMFCore.tests.base.testcase import RequestTest
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFTopic.Topic import Topic
+
 from common import CriterionTestCase
 
 
@@ -165,8 +165,10 @@
         PlacelessSetup.setUp(self)
         RequestTest.setUp(self)
         zcml.load_config('meta.zcml', Products.Five)
+        zcml.load_config('permissions.zcml', Products.Five)
         zcml.load_config('configure.zcml', Products.GenericSetup)
         zcml.load_config('configure.zcml', Products.CMFCore)
+        zcml.load_config('configure.zcml', Products.DCWorkflow)
 
         factory = self.root.manage_addProduct['CMFDefault'].addConfiguredSite
         factory('site', 'CMFDefault:default', snapshot=False)
@@ -384,10 +386,10 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(FriendlyDateCriterionTests),
-        makeSuite(FriendlyDateCriterionFunctionalTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(FriendlyDateCriterionTests),
+        unittest.makeSuite(FriendlyDateCriterionFunctionalTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/DCWorkflow/DCWorkflow.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/DCWorkflow.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/DCWorkflow.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -35,7 +35,6 @@
 from Products.CMFCore.WorkflowCore import ObjectDeleted
 from Products.CMFCore.WorkflowCore import ObjectMoved
 from Products.CMFCore.WorkflowCore import WorkflowException
-from Products.CMFCore.WorkflowTool import addWorkflowFactory
 
 # DCWorkflow
 from permissions import ManagePortal
@@ -66,7 +65,6 @@
     implements(IWorkflowDefinition)
     __implements__ = z2IWorkflowDefinition
 
-    meta_type = 'Workflow'
     title = 'DC Workflow Definition'
     _isAWorkflow = 1
 
@@ -537,7 +535,3 @@
             return new_sdef
 
 InitializeClass(DCWorkflowDefinition)
-
-
-addWorkflowFactory(DCWorkflowDefinition, id='dc_workflow',
-                   title='Web-configurable workflow')

Added: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/__init__.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/__init__.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/__init__.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -0,0 +1,16 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""DCWorkflow browser views.
+
+$Id$
+"""


Property changes on: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/addDCWorkflowDefinition.pt
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/addDCWorkflowDefinition.pt	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/addDCWorkflowDefinition.pt	2005-11-21 18:57:42 UTC (rev 40304)
@@ -0,0 +1,46 @@
+<h1 tal:replace="structure context/manage_page_header">PAGE HEADER</h1>
+<h2 tal:define="form_title view/title"
+    tal:replace="structure context/manage_form_title">FORM TITLE</h2>
+
+<p class="form-help" tal:content="view/description">DESCRIPTION TEXT.</p>
+
+<form action="." method="post"
+   tal:attributes="action request/ACTUAL_URL">
+<table cellspacing="0" cellpadding="2" border="0">
+ <tr>
+  <td>
+   <div class="form-label">ID</div>
+  </td>
+  <td>
+   <input type="text" name="add_input_name" size="40" />
+  </td>
+ </tr>
+ <tr tal:condition="view/getProfileInfos">
+  <td>
+   <div class="form-label">Presettings</div>
+  </td>
+  <td>
+   <select name="settings_id">
+    <option value="" selected="selected">(None)</option>
+    <optgroup label="PROFILE_TITLE"
+       tal:repeat="profile view/getProfileInfos"
+       tal:attributes="label profile/title">
+     <option value="SETTINGS_ID"
+             tal:repeat="obj_id profile/obj_ids"
+             tal:attributes="value string:${profile/id}/${obj_id}"
+             tal:content="obj_id">OBJ ID</option></optgroup>
+   </select>
+  </td>
+ </tr>
+ <tr>
+  <td>
+   &nbsp;
+  </td>
+  <td>
+   <input class="form-element" type="submit" name="submit_add" value="Add" /> 
+  </td>
+ </tr>
+</table>
+</form>
+
+<h1 tal:replace="structure context/manage_page_footer">PAGE FOOTER</h1>

Added: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/configure.zcml
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/configure.zcml	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/configure.zcml	2005-11-21 18:57:42 UTC (rev 40304)
@@ -0,0 +1,13 @@
+<configure
+    xmlns:browser="http://namespaces.zope.org/browser"
+    >
+
+  <browser:page
+      for="zope.app.container.interfaces.IAdding"
+      name="addDCWorkflowDefinition.html"
+      template="addDCWorkflowDefinition.pt"
+      class=".workflow.DCWorkflowDefinitionAddView"
+      permission="cmf.ManagePortal"
+      />
+
+</configure>


Property changes on: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""DCWorkflowDefinition browser views.
+
+$Id$
+"""
+
+from xml.dom.minidom import parseString
+
+from Products.CMFCore.utils import getToolByName
+
+from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
+
+
+class DCWorkflowDefinitionAddView:
+
+    """Add view for DCWorkflowDefinition.
+    """
+
+    title = u'Add DC Workflow Definition'
+
+    description = u'Add a web-configurable workflow.'
+
+    meta_type = DCWorkflowDefinition.meta_type
+
+    def __call__(self, add_input_name='', settings_id='', submit_add=''):
+        if submit_add:
+            if settings_id:
+                profile_id, obj_id = settings_id.split('/')
+                if not add_input_name:
+                    self.request.set('add_input_name', obj_id)
+            obj = DCWorkflowDefinition('temp')
+            self.context.add(obj)
+            self.request.response.redirect(self.context.nextURL())
+            return ''
+        return self.index()
+
+    def getProfileInfos(self):
+        profiles = []
+        stool = getToolByName(self, 'portal_setup', None)
+        if stool:
+            for info in stool.listContextInfos():
+                obj_ids = []
+                context = stool._getImportContext(info['id'])
+                dirnames = context.listDirectory('workflows')
+                for dirname in dirnames or ():
+                    filename = 'workflows/%s/definition.xml' % dirname
+                    body = context.readDataFile(filename)
+                    if body is None:
+                        continue
+                    root = parseString(body).documentElement
+                    obj_id = root.getAttribute('workflow_id')
+                    obj_ids.append(obj_id)
+                if not obj_ids:
+                    continue
+                obj_ids.sort()
+                profiles.append({'id': info['id'],
+                                 'title': info['title'],
+                                 'obj_ids': tuple(obj_ids)})
+        return tuple(profiles)


Property changes on: CMF/branches/yuppie-workflow_setup/DCWorkflow/browser/workflow.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: CMF/branches/yuppie-workflow_setup/DCWorkflow/configure.zcml
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/configure.zcml	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/configure.zcml	2005-11-21 18:57:42 UTC (rev 40304)
@@ -0,0 +1,15 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:five="http://namespaces.zope.org/five">
+
+  <include package=".browser"/>
+
+  <five:registerClass
+      class=".DCWorkflow.DCWorkflowDefinition"
+      meta_type="Workflow"
+      addview="addDCWorkflowDefinition.html"
+      permission="cmf.ManagePortal"
+      global="False"
+      />
+
+</configure>


Property changes on: CMF/branches/yuppie-workflow_setup/DCWorkflow/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_DCWorkflow.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_DCWorkflow.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_DCWorkflow.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,27 +15,21 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
-from Products.CMFCore.WorkflowTool import addWorkflowFactory
 from Products.CMFCore.WorkflowTool import WorkflowTool
 
 
-class DCWorkflowDefinitionTests(TestCase):
+class DCWorkflowDefinitionTests(unittest.TestCase):
 
     def setUp(self):
-        from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
-
         self.site = DummySite('site')
         self.site._setObject( 'portal_types', DummyTool() )
         self.site._setObject( 'portal_workflow', WorkflowTool() )
-        addWorkflowFactory(DCWorkflowDefinition)
         self._constructDummyWorkflow()
 
     def test_z2interfaces(self):
@@ -54,9 +48,10 @@
         verifyClass(IWorkflowDefinition, DCWorkflowDefinition)
 
     def _constructDummyWorkflow(self):
+        from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
 
         wftool = self.site.portal_workflow
-        wftool.manage_addWorkflow('Workflow (DC Workflow Definition)', 'wf')
+        wftool._setObject('wf', DCWorkflowDefinition('wf'))
         wftool.setDefaultChain('wf')
         wf = wftool.wf
 
@@ -128,9 +123,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(DCWorkflowDefinitionTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(DCWorkflowDefinitionTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_guard.py
===================================================================
--- CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_guard.py	2005-11-21 18:28:54 UTC (rev 40303)
+++ CMF/branches/yuppie-workflow_setup/DCWorkflow/tests/test_guard.py	2005-11-21 18:57:42 UTC (rev 40304)
@@ -15,32 +15,31 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
+import Testing
 
 from AccessControl import getSecurityManager
 from Products.PageTemplates.TALES import CompilerError
 
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.WorkflowTool import WorkflowTool
-from Products.CMFCore.WorkflowTool import addWorkflowFactory
 
 from Products.DCWorkflow.Guard import Guard
 from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
 
-from Products.CMFCore.tests.base.dummy import DummyContent
-from Products.CMFCore.tests.base.dummy import DummySite
-from Products.CMFCore.tests.base.dummy import DummyTool
 
-class TestGuard(TestCase):
+class TestGuard(unittest.TestCase):
 
     def setUp(self):
         self.site = DummySite('site')
         self.site._setObject( 'portal_types', DummyTool() )
         self.site._setObject( 'portal_workflow', WorkflowTool() )
-        addWorkflowFactory(DCWorkflowDefinition)
 
         # Construct a workflow
         wftool = self.site.portal_workflow
-        wftool.manage_addWorkflow('Workflow (DC Workflow Definition)', 'wf')
+        wftool._setObject('wf', DCWorkflowDefinition('wf'))
         wftool.setDefaultChain('wf')
 
     def _getDummyWorkflow(self):
@@ -260,11 +259,11 @@
 
         # XXX more tests with permissions and roles
 
+
 def test_suite():
-    return TestSuite((
-        makeSuite(TestGuard),
+    return unittest.TestSuite((
+        unittest.makeSuite(TestGuard),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
-
+    unittest.main(defaultTest='test_suite')



More information about the CMF-checkins mailing list