[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Workflow/Stateful - ContentWorkflowsUtility.py:1.1.2.1 IContentWorkflowsUtility.py:1.1.2.1 basic_wf_state.pt:1.1.2.1 configure.zcml:1.1.2.1 subscription_control.pt:1.1.2.1 StatefulProcessDefinition.py:1.1.2.2

Florent Guillaume fg@nuxeo.com
Fri, 6 Dec 2002 11:04:09 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Workflow/Stateful
In directory cvs.zope.org:/tmp/cvs-serv6178/Stateful

Modified Files:
      Tag: sprintathon-wf-branch
	StatefulProcessDefinition.py 
Added Files:
      Tag: sprintathon-wf-branch
	ContentWorkflowsUtility.py IContentWorkflowsUtility.py 
	basic_wf_state.pt configure.zcml subscription_control.pt 
Log Message:
Checkpoint.
Adding a beginning of entity-base workflow tool.
Tests pass, Zope starts.


=== Added File Zope3/lib/python/Zope/App/Workflow/Stateful/ContentWorkflowsUtility.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.
#
##############################################################################
"""Content Workflows Utility

Associates content objects with some workflow process definitions.

$Id: ContentWorkflowsUtility.py,v 1.1.2.1 2002/12/06 16:04:08 efge Exp $
"""
__metaclass__ = type

from Interface import Interface
from Persistence import Persistent
from Zope.ComponentArchitecture import getService, getAdapter
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Zope.ContextWrapper import ContextMethod
from Zope.Event.ISubscriber import ISubscriber
from Zope.App.OFS.Services.ObjectHub.IHubEvent import IRegistrationHubEvent
from Zope.App.OFS.Services.ObjectHub.IHubEvent import IObjectRegisteredHubEvent
from Zope.App.OFS.Services.ObjectHub.IHubEvent import IObjectUnregisteredHubEvent

from Zope.App.Workflow.IProcessInstanceContainer \
     import IProcessInstanceContainer
from Zope.App.Workflow.Stateful.IContentWorkflowsUtility \
     import IContentWorkflowsUtility


class ContentWorkflowsUtility(Persistent):

    __implements__ = IContentWorkflowsUtility, ISubscriber

    def __init__(self):
        super(ContentWorkflowsUtility, self).__init__()
        self._names = () # _names should be a field

    # ISubscriber

    def notify(self, event):
        """An event occured. Perhaps register this object with the hub."""
        try:
            container = getAdapter(event.object, IProcessInstanceContainer)
        except ComponentLookupError:
            # Object can't have associated PIs.
            return
        if IObjectRegisteredHubEvent.isImplementedBy(event):
            #texts = self._getTexts(event.object)
            # self.index_doc(event.hubid, texts)
            wfs = getService(self, "Workflows")
            for pd_name in self._names:
                try:
                    pi = wfs.createProcessInstance(pd_name)
                except KeyError:
                    # No registered PD with that name..
                    continue
                # XXX What happens if there's already a pi with that name?
                container[pd_name] = pi
        elif IObjectUnregisteredHubEvent.isImplementedBy(event):
            for pd_name in self._names:
                if pd_name in container:
                    del container[pd_name]
    notify = ContextMethod(notify)

    # IContentWorkflowsUtility

    # control

    currentlySubscribed = False # Default subscription state

    def subscribe(self):
        if self.currentlySubscribed:
            raise RuntimeError, "already subscribed; please unsubscribe first"
        channel = self._getChannel(None)
        channel.subscribe(self, IRegistrationHubEvent)
        self.currentlySubscribed = True
    subscribe = ContextMethod(subscribe)

    def unsubscribe(self):
        if not self.currentlySubscribed:
            raise RuntimeError, "not subscribed; please subscribe first"
        channel = self._getChannel(None)
        channel.unsubscribe(self, IRegistrationHubEvent)
        self.currentlySubscribed = False
    unsubscribe = ContextMethod(unsubscribe)

    def isSubscribed(self):
        return self.currentlySubscribed

    def _getChannel(self, channel):
        if channel is None:
            channel = getService(self, "ObjectHub")
        return channel
    _getChannel = ContextMethod(_getChannel)

    # config

    def getProcessDefinitionNames(self):
        """Get the process definition names."""
        return self._names

    def setProcessDefinitionNames(self, names):
        """Set the process definition names."""
        self._names = tuple(names)



=== Added File Zope3/lib/python/Zope/App/Workflow/Stateful/IContentWorkflowsUtility.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.
#
##############################################################################
"""Content Workflows Utility Interface

$Id: IContentWorkflowsUtility.py,v 1.1.2.1 2002/12/06 16:04:08 efge Exp $
"""

from Interface import Interface


class IContentWorkflowsUtility(Interface):
    """A Content Workflows Utility, which associates content objects
    with some workflow process definitions.
    """

    def subscribe():
        """Subscribe to the prevailing object hub service."""

    def unsubscribe():
        """Unsubscribe from the object hub service."""

    def isSubscribed():
        """Return whether we are currently subscribed."""

    def getProcessDefinitionNames():
        """Get the process definition names."""

    def setProcessDefinitionNames(names):
        """Set the process definition names."""


=== Added File Zope3/lib/python/Zope/App/Workflow/Stateful/basic_wf_state.pt ===
This should display the wf state of this object...


=== Added File Zope3/lib/python/Zope/App/Workflow/Stateful/configure.zcml ===
<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:browser='http://namespaces.zope.org/browser'
   >

  <content class=".ContentWorkflowUtility.">
    <require
      permission="Zope.ManageServices"
      interface=".Subscriber.ISubscriptionControl"
      />
    <factory
      id="Zope.App.Workflow.Stateful.ContentWorkflowUtility."
      permission="Zope.ManageServices"
      />
  </content>

  <browser:menuItem
    menu="add_component"
    for="Zope.App.OFS.Container.IAdding."
    action="Zope.App.index.subscribers.Registration"
    title="Registration subscriber"
    description="An event subscriber that registers content with the objecthub"
    />

  <browser:defaultView
    for=".Subscriber.ISubscriptionControl"
    name="control.html" />

  <browser:view
    for=".Subscriber.ISubscriptionControl"
    permission="Zope.ManageServices"
    name="control.html"
    template="subscription_control.pt" />


  <!-- Viewing state of objects -->

  <browser:view for="Zope.App.OFS.Annotation.IAnnotatable."
                permission="Zope.ManageContent"
                factory=".BasicWorkflowStateView.">
    <browser:page name="WorkflowState.html"
                  template="basic_wf_state.pt" />
  </browser:view>

  <browser:menuItems menu="zmi_views"
      for="Zope.App.Workflow.IProcessInstanceContainerAdaptable.">
    <browser:menuItem title="Workflow State" action="@@WorfklowState.html"/>
  </browser:menuItems>


</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/Workflow/Stateful/subscription_control.pt ===
<html metal:use-macro="views/standard_macros/page">

  <head>
    <title>Registration "Service" Control Page</title>
  </head>

  <body>

  <div metal:fill-slot="body">

    <h1>Subscription control</h1>

    <span tal:condition="request/callSubscribe|nothing" tal:omit-tag="">
        <span tal:define="dummy context/subscribe" tal:omit-tag=""/>
    </span>
    <span tal:condition="request/callUnsubscribe|nothing" tal:omit-tag="">
        <span tal:define="dummy context/unsubscribe" tal:omit-tag=""/>
    </span>

    <form method="POST">
       <span tal:condition="context/isSubscribed" tal:omit-tag="">
           Subscription state: ON
           <input type="submit" value="Unsubscribe" name="callUnsubscribe" />
       </span>
       <span tal:condition="not:context/isSubscribed" tal:omit-tag="">
           Subscription state: OFF
           <input type="submit" value="Subscribe" name="callSubscribe" />
       </span>
    </form>

  </div>

  </body>

</html>


=== Zope3/lib/python/Zope/App/Workflow/Stateful/StatefulProcessDefinition.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/lib/python/Zope/App/Workflow/Stateful/StatefulProcessDefinition.py:1.1.2.1	Thu Dec  5 11:44:39 2002
+++ Zope3/lib/python/Zope/App/Workflow/Stateful/StatefulProcessDefinition.py	Fri Dec  6 11:04:08 2002
@@ -54,6 +54,9 @@
     def addState(self, name, state):
         pass
 
+    def getState(self, name):
+        return None
+
     def removeState(self, name):
         pass
 
@@ -65,6 +68,9 @@
 
     def addTransition(self, name, transition):
         pass
+
+    def getTransition(self, name):
+        return None
 
     def removeTransition(self, name):
         pass