[Zope-CVS] CVS: Packages3/workflow - definition.py:1.2 instance.py:1.3 service.py:1.3
Ulrich Eck
ueck@net-labs.de
Wed, 5 Feb 2003 20:10:01 -0500
Update of /cvs-repository/Packages3/workflow
In directory cvs.zope.org:/tmp/cvs-serv29874
Modified Files:
definition.py instance.py service.py
Log Message:
- new ProcessDefinitionElementContainer
- extended tests
- Stateful ProcessDefinition/Instance:
+ basic functionality for Instance (getOutgoingTransitions/fireTransition)
- no relevant-data, conditions yet
- Added views for basic TTW interaction
=== Packages3/workflow/definition.py 1.1 => 1.2 ===
--- Packages3/workflow/definition.py:1.1 Sun Feb 2 14:21:53 2003
+++ Packages3/workflow/definition.py Wed Feb 5 20:09:29 2003
@@ -17,8 +17,12 @@
"""
__metaclass__ = type
+from types import StringTypes
from persistence import Persistent
-from zope.app.interfaces.workflow import IProcessDefinition
+from persistence.dict import PersistentDict
+from zope.proxy.context import ContextAware
+from zope.app.interfaces.workflow \
+ import IProcessDefinition, IProcessDefinitionElementContainer
class ProcessDefinition(Persistent):
@@ -38,3 +42,72 @@
#
############################################################
+
+
+
+
+
+class ProcessDefinitionElementContainer(ContextAware, Persistent):
+ """ See IProcessDefinitionElementContainer.
+ """
+
+ __implements__ = IProcessDefinitionElementContainer
+
+ def __init__(self):
+ super(ProcessDefinitionElementContainer, self).__init__()
+ self.__data = PersistentDict()
+
+ def keys(self):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data.keys()
+
+ def __iter__(self):
+ return iter(self.__data.keys())
+
+ def __getitem__(self, key):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data[key]
+
+ def get(self, key, default=None):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data.get(key, default)
+
+ def values(self):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data.values()
+
+ def __len__(self):
+ '''See interface IProcessDefinitionElementContainer'''
+ return len(self.__data)
+
+ def items(self):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data.items()
+
+ def __contains__(self, key):
+ '''See interface IProcessDefinitionElementContainer'''
+ return self.__data.has_key(key)
+
+ has_key = __contains__
+
+ def setObject(self, key, object):
+ '''See interface IProcessDefinitionElementContainer'''
+ bad = False
+ if isinstance(key, StringTypes):
+ try:
+ unicode(key)
+ except UnicodeError:
+ bad = True
+ else:
+ bad = True
+ if bad:
+ raise TypeError("'%s' is invalid, the key must be an "
+ "ascii or unicode string" % key)
+ if len(key) == 0:
+ raise ValueError("The key cannot be an empty string")
+ self.__data[key] = object
+ return key
+
+ def __delitem__(self, key):
+ '''See interface IProcessDefinitionElementContainer'''
+ del self.__data[key]
=== Packages3/workflow/instance.py 1.2 => 1.3 ===
--- Packages3/workflow/instance.py:1.2 Tue Feb 4 16:38:06 2003
+++ Packages3/workflow/instance.py Wed Feb 5 20:09:29 2003
@@ -18,7 +18,11 @@
__metaclass__ = type
from persistence import Persistent
-from zope.app.interfaces.workflow import IProcessInstance
+from zope.proxy.context import ContextWrapper
+
+from zope.app.interfaces.annotation import IAnnotatable
+from zope.app.interfaces.workflow \
+ import IProcessInstance, IProcessInstanceContainer
# XXX should an Instance be persistent by default ???
@@ -28,22 +32,115 @@
__implements__ = IProcessInstance
- def __init__(self, pd_name, initial_status):
+ def __init__(self, pd_name):
self._pd_name = pd_name
- self._status = initial_status
+ self._status = None
- processDefinitionName = property(lambda self: self._pd_name)
-
- status = property(lambda self: self._status)
-
############################################################
# Implementation methods for interface
# zope.app.interfaces.workflow.IProcessInstance
+ processDefinitionName = property(lambda self: self._pd_name)
+
+ status = property(lambda self: self._status)
#
############################################################
+
+
+
+
+
+
+
+
+
+
+
+
+WFKey = "zope.app.worfklow.ProcessInstanceContainer"
+
+class ProcessInstanceContainerAdapter:
+
+ __implements__ = IProcessInstanceContainer
+
+ __used_for__ = IAnnotatable
+
+ def __init__(self, context):
+ self.context = context
+ annotations = getAdapter(context, IAnnotations)
+ wfdata = annotations.get(WFKey)
+ if not wfdata:
+ wfdata = PersistentDict()
+ annotations[WFKey] = wfdata
+ self.wfdata = wfdata
+
+ def __getitem__(self, key):
+ "See IProcessInstanceContainer"
+ value = self.wfdata[key]
+ return ContextWrapper(value, self.context, name=key)
+
+ def get(self, key, default=None):
+ "See IProcessInstanceContainer"
+ value = self.wfdata.get(key, _marker)
+ if value is not _marker:
+ return ContextWrapper(value, self.context, name=key)
+ else:
+ return default
+
+ def __contains__(self, key):
+ "See IProcessInstanceContainer"
+ return key in self.wfdata
+
+
+ def values(self):
+ "See IProcessInstanceContainer"
+ container = self.wfdata
+ result = []
+ for key, value in container.items():
+ result.append(ContextWrapper(value, self.context, name=key))
+ return result
+
+ def keys(self):
+ "See IProcessInstanceContainer"
+ return self.wfdata.keys()
+
+ def __len__(self):
+ "See IProcessInstanceContainer"
+ return len(self.wfdata)
+
+ def items(self):
+ "See IProcessInstanceContainer"
+ container = self.wfdata
+ result = []
+ for key, value in container.items():
+ result.append((key, ContextWrapper(value, self.context, name=key)))
+ return result
+
+ def setObject(self, key, object):
+ "See IProcessInstanceContainer"
+
+ if not isinstance(key, StringTypes):
+ raise TypeError("Item name is not a string.")
+
+ container = self.wfdata
+ object = removeAllProxies(object)
+ container[key] = object
+ # publish event ??
+ return key
+
+
+ def __delitem__(self, key):
+ "See IZopeWriteContainer"
+ container = self.wfdata
+ # publish event ?
+ del container[key]
+ return key
+
+ def __iter__(self):
+ '''See interface IReadContainer'''
+ return iter(self.context)
=== Packages3/workflow/service.py 1.2 => 1.3 ===
--- Packages3/workflow/service.py:1.2 Tue Feb 4 16:38:06 2003
+++ Packages3/workflow/service.py Wed Feb 5 20:09:29 2003
@@ -20,7 +20,7 @@
from persistence import Persistent
-from zope.proxy.context import ContextMethod
+from zope.proxy.context import ContextMethod, ContextWrapper
from zope.app.component.nextservice import queryNextService
from zope.app.interfaces.services.configuration \
@@ -70,7 +70,7 @@
'See IWorkflowService'
pd = self.queryActiveComponent(name)
if pd is not None:
- return pd
+ return ContextWrapper(pd, self, name=name)
service = queryNextService(self, "Workflows")
if service is not None:
return service.getProcessDefinition(name)