[Zope3-checkins] CVS: Zope3/src/zope/app/workflow - configure.zcml:1.3 service.py:1.9

Stephan Richter srichter@cosmos.phy.tufts.edu
Tue, 29 Jul 2003 20:00:57 -0400


Update of /cvs-repository/Zope3/src/zope/app/workflow
In directory cvs.zope.org:/tmp/cvs-serv20793/src/zope/app/workflow

Modified Files:
	configure.zcml service.py 
Log Message:
Workflow enhancements to make them more useful. (More to come)

- ContentWorkflowsUtility has been renamed to ContentWorkflowsManager

- Specific Process Definitions can now be mapped to interfaces (later 
  content types), so that a content type only receives the workflows that
  were inteneded for it.

- Supplied a management screen for the above.

- Wrote a bunch of tests for ContentWorkflowsManager.

- Added a default screen to the Workflow Service, which lists all registered
  process definitions.


=== Zope3/src/zope/app/workflow/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/workflow/configure.zcml:1.2	Sat Jun 21 17:22:15 2003
+++ Zope3/src/zope/app/workflow/configure.zcml	Tue Jul 29 20:00:22 2003
@@ -2,7 +2,6 @@
    xmlns='http://namespaces.zope.org/zope'
    xmlns:service='http://namespaces.zope.org/service'>
 
-
 <!-- Workflow Permissions -->
 
 <permission 
@@ -37,12 +36,11 @@
 </content>
 
 <serviceType 
-  id='Workflows'
-  interface='zope.app.interfaces.workflow.IWorkflowService' 
+  id="Workflows"
+  interface="zope.app.interfaces.workflow.IWorkflowService"
   />
 
 
-
 <!-- Workflow Process Definition 
      This is only a generic placeholder for
      future Process Definition implementations
@@ -85,6 +83,20 @@
       />
 </content>
 
+<vocabulary
+   name="ProcessDefinitions"
+   factory=".service.ProcessDefinitionVocabulary" />
+
+<content class=".service.ProcessDefinitionVocabulary">
+  <allow interface="zope.schema.interfaces.IVocabulary"/>
+  <allow interface="zope.schema.interfaces.IVocabularyTokenized"/>
+  <allow attributes="__contains__"/>
+</content>
+
+<content class=".service.ProcessDefinitionTerm">
+  <allow interface="zope.schema.interfaces.ITokenizedTerm"/>
+</content>
+
 
 <!-- Process Instance Container -->
 
@@ -112,7 +124,6 @@
          for="zope.app.interfaces.annotation.IAnnotatable" />
 
 <!-- Workflow Import/Export Utility -->
-
 <utility
     component=".globalimportexport.globalImportExport" 
     provides="zope.app.interfaces.workflow.IProcessDefinitionImportExport"


=== Zope3/src/zope/app/workflow/service.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/workflow/service.py:1.8	Sun Jun 22 20:31:32 2003
+++ Zope3/src/zope/app/workflow/service.py	Tue Jul 29 20:00:22 2003
@@ -19,6 +19,7 @@
 __metaclass__ = type
 
 from persistence import Persistent
+from zope.component import getService
 from zope.app.component.nextservice import queryNextService
 from zope.app.context import ContextWrapper
 from zope.app.interfaces.services.registration import INameComponentRegistry
@@ -29,10 +30,13 @@
 from zope.app.interfaces.workflow import IWorkflowService
 from zope.app.services.registration import NameComponentRegistry
 from zope.app.services.registration import NamedComponentRegistration
+from zope.app.services.servicenames import Workflows
 from zope.app.traversing import getPath
 from zope.component import getAdapter
 from zope.context import ContextMethod
 from zope.interface import implements
+from zope.schema.interfaces import \
+     ITokenizedTerm, IVocabulary, IVocabularyTokenized
 
 
 class ILocalWorkflowService(IWorkflowService, INameComponentRegistry):
@@ -57,7 +61,7 @@
             registry = self.queryRegistrations(name)
             if registry.active() is not None:
                 definition_names[name] = 0
-        service = queryNextService(self, "Workflows")
+        service = queryNextService(self, Workflows)
         if service is not None:
             for name in service.getProcessDefinitionNames():
                 definition_names[name] = 0
@@ -66,12 +70,13 @@
     getProcessDefinitionNames = ContextMethod(getProcessDefinitionNames)
 
 
+
     def getProcessDefinition(self, name):
         'See IWorkflowService'
         pd = self.queryActiveComponent(name)
         if pd is not None:
             return ContextWrapper(pd, self, name=name)
-        service = queryNextService(self, "Workflows")
+        service = queryNextService(self, Workflows)
         if service is not None:
             return service.getProcessDefinition(name)
         raise KeyError, name
@@ -105,7 +110,7 @@
 
     implements(IProcessDefinitionRegistration)
 
-    serviceType = 'Workflows'
+    serviceType = Workflows
 
     def getInterface(self):
         return IProcessDefinition
@@ -135,3 +140,40 @@
         adapter.removeUsage(getPath(registration))
         super(ProcessDefinitionRegistration, self).beforeDeleteHook(
             registration, container)
+
+
+class ProcessDefinitionTerm:
+
+    implements(ITokenizedTerm)
+
+    def __init__(self, name):
+        self.value = name
+        self.token = name
+
+
+class ProcessDefinitionVocabulary(object):
+
+    implements(IVocabulary, IVocabularyTokenized)
+
+    def __init__(self, context):
+        self.workflows = getService(context, Workflows)
+    
+    def __contains__(self, value):
+        return value in self.workflows.getProcessDefinitionNames()
+    
+    def __iter__(self):
+        terms = map(lambda p: ProcessDefinitionTerm(p),
+                    self.workflows.getProcessDefinitionNames())
+        return iter(terms)
+    
+    def __len__(self):
+        return len(self.workflows.getProcessDefinitionNames())
+    
+    def getQuery(self):
+        return None
+    
+    def getTerm(self, value):
+        return ProcessDefinitionTerm(value)
+
+    def getTermByToken(self, token):
+        return self.getTerm(token)