[Zope3-checkins] CVS: Zope3/src/zope/app/workflow - definition.py:1.9

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Apr 15 18:11:18 EDT 2004


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

Modified Files:
	definition.py 
Log Message:


Moved Process Definition Vocabulary here.




=== Zope3/src/zope/app/workflow/definition.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/workflow/definition.py:1.8	Wed Mar  3 15:20:33 2004
+++ Zope3/src/zope/app/workflow/definition.py	Thu Apr 15 18:11:17 2004
@@ -20,7 +20,12 @@
 
 from zope.interface import implements
 
+from zope.schema.interfaces import ITokenizedTerm
+from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
+
+from zope.app import zapi
 from zope.app.container.contained import Contained, setitem, uncontained
+from zope.app.servicenames import Utilities
 from zope.app.workflow.interfaces import IProcessDefinitionElementContainer
 from zope.app.workflow.interfaces import IProcessDefinition
 
@@ -90,3 +95,48 @@
 
     def getProcessDefinition(self):
         return self.__parent__
+
+
+class ProcessDefinitionTerm:
+    """A term representing the name of a process definition."""
+    implements(ITokenizedTerm)
+
+    def __init__(self, name):
+        self.value = self.token = name
+
+
+class ProcessDefinitionVocabulary:
+    """Vocabulary providing available process definition names."""
+    implements(IVocabulary, IVocabularyTokenized)
+
+    def __init__(self, context):
+        self.utilities = zapi.getService(context, Utilities)
+
+    def __names(self):
+        return [name for name, util in self.utilities.getUtilitiesFor(
+                                            IProcessDefinition)]
+
+    def __contains__(self, value):
+        """See zope.schema.interfaces.IVocabulary"""
+        return value in self.__names()
+
+    def __iter__(self):
+        """See zope.schema.interfaces.IVocabulary"""
+        terms = [ProcessDefinitionTerm(name) for name in self.__names()]
+        return iter(terms)
+
+    def __len__(self):
+        """See zope.schema.interfaces.IVocabulary"""
+        return len(self.__names())
+
+    def getQuery(self):
+        """See zope.schema.interfaces.IVocabulary"""
+        return None
+
+    def getTerm(self, value):
+        """See zope.schema.interfaces.IVocabulary"""
+        return ProcessDefinitionTerm(value)
+
+    def getTermByToken(self, token):
+        """See zope.schema.interfaces.IVocabularyTokenized"""
+        return self.getTerm(token)




More information about the Zope3-Checkins mailing list