[Zope-CVS] CVS: Packages3/workflow/stateful - xmlexport_template.pt:1.1 xmlimportexport.py:1.1 configure.zcml:1.7 definition.py:1.5 instance.py:1.7

Ulrich Eck ueck@net-labs.de
Wed, 26 Mar 2003 12:43:39 -0500


Update of /cvs-repository/Packages3/workflow/stateful
In directory cvs.zope.org:/tmp/cvs-serv13635/stateful

Modified Files:
	configure.zcml definition.py instance.py 
Added Files:
	xmlexport_template.pt xmlimportexport.py 
Log Message:
first round of checkin of our sprint work (some test are missing)


=== Added File Packages3/workflow/stateful/xmlexport_template.pt ===
<workflows>
  <processdefinition>
   some information
  </processdefinition>
</workflows>

=== Added File Packages3/workflow/stateful/xmlimportexport.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Stateful ProcessDefinition XML Import/Export handlers

$Id: xmlimportexport.py,v 1.1 2003/03/26 17:43:38 jack-e Exp $
"""
__metaclass__ = type

from zope.app.pagetemplate.viewpagetemplatefile \
     import ViewPageTemplateFile
from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
from zope.app.interfaces.workflow import IProcessDefinitionExportHandler

class XMLImportHandler:

    __implements__ = IProcessDefinitionImportHandler

    def canImport(self, data):
        return True

    def doImport(self, data):
        return 'The Process Definition'
    

class XMLExportHandler:

    __implements__ = IProcessDefinitionExportHandler

    template = ViewPageTemplateFile('xmlexport_template.pt')

    def doExport(self, process_definition):
        # XXX Not really nice to fake a BrowserView here ....
        self.request = None
        self.context = process_definition
        return self.template()




=== Packages3/workflow/stateful/configure.zcml 1.6 => 1.7 ===
--- Packages3/workflow/stateful/configure.zcml:1.6	Wed Mar 26 10:24:27 2003
+++ Packages3/workflow/stateful/configure.zcml	Wed Mar 26 12:43:38 2003
@@ -108,7 +108,6 @@
 </content>
 
 <!-- Stateful workflow import/Export -->
-<!--
 <workflow:importHandler
    interface="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
    factory=".xmlimportexport.XMLImportHandler"
@@ -118,5 +117,5 @@
    interface="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
    factory=".xmlimportexport.XMLExportHandler"
    />
--->
+
 </zopeConfigure>


=== Packages3/workflow/stateful/definition.py 1.4 => 1.5 ===
--- Packages3/workflow/stateful/definition.py:1.4	Fri Feb  7 10:29:30 2003
+++ Packages3/workflow/stateful/definition.py	Wed Mar 26 12:43:38 2003
@@ -51,19 +51,19 @@
     __implements__ = IStatefulStatesContainer
 
 
-
 class Transition(Persistent):
     """Transition."""
 
     __implements__ = ITransition
 
-    def __init__(self, source=None, destination=None, condition=None, permission=None,
-                 name=None, description=None):
+    def __init__(self, source=None, destination=None, condition=None,
+                 permission=None, triggerMode=None):
         super(Transition, self).__init__()
         self.__source = source
         self.__destination = destination
         self.__condition = condition
         self.__permission = permission
+        self.__triggerMode = triggerMode
 
 
     def getSourceState(self):
@@ -90,6 +90,11 @@
     def setPermission(self, permission):
         self.__permission = permission or None
 
+    def getTriggerMode(self):
+        return self.__triggerMode
+
+    def setTriggerMode(self, mode):
+        self.__triggerMode = mode
 
     # See ITransition
     sourceState = property(getSourceState, setSourceState, None,
@@ -104,6 +109,8 @@
     permission = property(getPermission, setPermission, None,
                           "Permission for Transition.")
 
+    triggerMode = property(getTriggerMode, setTriggerMode, None,
+                           "TriggerMode for Transition.")
 
     def getProcessDefinition(self):
         return getWrapperContainer(self).getProcessDefinition()
@@ -115,7 +122,6 @@
     """Container that stores Transitions.
     """
     __implements__ = IStatefulTransitionsContainer
-
 
 
 


=== Packages3/workflow/stateful/instance.py 1.6 => 1.7 ===
--- Packages3/workflow/stateful/instance.py:1.6	Sat Feb  8 11:52:27 2003
+++ Packages3/workflow/stateful/instance.py	Wed Mar 26 12:43:38 2003
@@ -84,9 +84,12 @@
         if type(schema) in StringTypes:
             sm = getServiceManager(self)
             schema =  sm.resolve(schema)
-            
-        # create relevant-data
-        self._data = self._buildRelevantData(schema)
+
+        if schema:
+            # create relevant-data
+            self._data = self._buildRelevantData(schema)
+        else:
+            self._data = None
         # setup permission on data
        
     initialize = ContextMethod(initialize)
@@ -131,6 +134,8 @@
         trans = clean_pd.transitions[id]
         # modify relevant-data if needed
         self._status = trans.destinationState
+        # check for automatic transitions
+        self._checkAndFireAuto()
     fireTransition = ContextMethod(fireTransition)
 
     #
@@ -172,3 +177,14 @@
                 setattr(data, name, field.default)
         return data
 
+    def _checkAndFireAuto(self):
+        pd = self._getProcessDefinition()
+        clean_pd = removeAllProxies(pd)
+        outgoing_transitions = self.getOutgoingTransitions()
+        for name in outgoing_transitions:
+            trans = clean_pd.transitions[name]
+            if trans.triggerMode == 'Automatic':
+                self.fireTransitions(name)
+                return
+    
+    _checkAndFireAuto = ContextMethod(_checkAndFireAuto)