[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - add_svc_config.pt:1.1.2.1 configure.zcml:1.20.2.3 service.py:1.6.2.7 useconfiguration.pt:1.1.2.4

Guido van Rossum guido@python.org
Mon, 3 Mar 2003 16:33:09 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv27629

Modified Files:
      Tag: use-config-branch
	configure.zcml service.py useconfiguration.pt 
Added Files:
      Tag: use-config-branch
	add_svc_config.pt 
Log Message:
Refactored service creation/configuration again.  When you create a
service, its configuration is not created right away, but you're
directed to a page where you can:
- create configuration records
- activate them
for each service implemented by the service.

There's also a link there from the "Configurations" tab to add new
configurations.

Also did some cleanup of the zcml to remove the browser: namespace.


=== Added File Zope3/src/zope/app/browser/services/add_svc_config.pt ===
<html metal:use-macro="context/@@standard_macros/page">
  <body>
    <div metal:fill-slot="body">

      <form action="add_svc_config.html">

        <p>Configure this object to provide the following service(s):

        <table>

          <thead>
            <tr>
              <th>Configure</th>
              <th>Service name</th>
              <th>Activate</th>
            </tr>
          </thead>

          <tbody>
	    <tr tal:repeat="item view/listServiceTypes">

	      <td>
		<input type="checkbox" name="name:list" value="value" checked
		       tal:attributes="value item/name">
              </td>
	      <td tal:content="item/name">Events
	      </td>

	      <td>
		<input type="checkbox" name="active:list" value="value"
		       tal:attributes="value item/name;
				       checked item/checked">
	      </td>

	    </tr>
          </tbody>

	</table>

	<input type="reset" value="Reset form">
        <input type="submit" value="Submit">


      </form>

    </div>
  </body>
</html>


=== Zope3/src/zope/app/browser/services/configure.zcml 1.20.2.2 => 1.20.2.3 === (910/1010 lines abridged)
--- Zope3/src/zope/app/browser/services/configure.zcml:1.20.2.2	Mon Mar  3 15:07:22 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Mon Mar  3 16:33:08 2003
@@ -1,23 +1,22 @@
 <zopeConfigure
-   xmlns='http://namespaces.zope.org/zope'
-   xmlns:browser='http://namespaces.zope.org/browser'
+   xmlns='http://namespaces.zope.org/browser'
    >
 
 <!--Error Reporting Service -->
 
-  <browser:pages
+  <pages
     for="zope.app.interfaces.services.error.IErrorReportingService"
     permission="zope.Public"
     class="zope.app.browser.services.error.EditErrorLog">
 
-    <browser:page name="index.html" template="error.pt" />
-    <browser:page name="edit.html" attribute="updateProperties" />
-    <browser:page name="showEntry.html" template="errorentry.pt"/>
-    <browser:page name="showTextTBEntry.html"
+    <page name="index.html" template="error.pt" />
+    <page name="edit.html" attribute="updateProperties" />
+    <page name="showEntry.html" template="errorentry.pt"/>
+    <page name="showTextTBEntry.html"
        template="texttbentry.pt"/>
-    </browser:pages>
+    </pages>
 
-  <browser:menuItem
+  <menuItem
      menu="add_service"
      for="zope.app.interfaces.container.IAdding" 
      action="ErrorReportingService"
@@ -25,11 +24,11 @@
      description="Error Reporting Service for Logging Errors"
      />
   
-  <browser:icon name="zmi_icon" 
+  <icon name="zmi_icon" 
       for="zope.app.interfaces.services.error.IErrorReportingService" 
       file="error_service.gif" />
 
-  <browser:menuItem
+  <menuItem
       for="zope.app.interfaces.services.error.IErrorReportingService" 
       menu="zmi_views"
       title="Errors"
@@ -38,13 +37,13 @@
 

[-=- -=- -=- 910 lines omitted -=- -=- -=-]

     name="index.html" 
     menu="zmi_views" title="Control"
     permission="zope.ManageServices" 
@@ -852,7 +846,7 @@
     attribute="index" 
     />
 
-  <browser:menuItem
+  <menuItem
       menu="add_service"
       for="zope.app.interfaces.container.IAdding"
       action="ObjectHub"
@@ -861,7 +855,7 @@
                    more: use sparingly" 
       />
 
-  <browser:icon
+  <icon
       name="zmi_icon"
       for="zope.app.interfaces.services.hub.IObjectHub" 
       file="hub.gif" />
@@ -869,7 +863,7 @@
 
 <!-- "Add Service" menu -->
 
-<browser:menuItem
+<menuItem
     menu="add_component"
     for="zope.app.interfaces.container.IAdding"
     action="../AddService"
@@ -878,15 +872,15 @@
     permission="zope.ManageServices"
     />
 
-  <browser:view
+  <view
      name="AddService"
      for="zope.app.interfaces.services.package.IPackage"
      permission="zope.ManageServices"
      class="zope.app.browser.services.service.ServiceAdding">
 
-    <browser:page name="index.html"  attribute="index"  />
-    <browser:page name="action.html" attribute="action" />
+    <page name="index.html"  attribute="index"  />
+    <page name="action.html" attribute="action" />
 
-  </browser:view>
+  </view>
 
 </zopeConfigure>


=== Zope3/src/zope/app/browser/services/service.py 1.6.2.6 => 1.6.2.7 ===
--- Zope3/src/zope/app/browser/services/service.py:1.6.2.6	Mon Mar  3 15:07:22 2003
+++ Zope3/src/zope/app/browser/services/service.py	Mon Mar  3 16:33:08 2003
@@ -27,6 +27,9 @@
 from zope.app.form.utility import setUpWidgets, getWidgetsDataForContent
 from zope.app.traversing import traverse, getPhysicalPathString
 from zope.app.interfaces.services.interfaces import ILocalService
+from zope.proxy.context import getWrapperContainer
+from zope.app.interfaces.services.configuration \
+     import Unregistered, Registered, Active
 
 __metaclass__ = type
 
@@ -79,34 +82,8 @@
         if not ILocalService.isImplementedBy(self.added_object):
             raise TypeError("%s is not a local service" % self.added_object)
 
-        # Collect all defined services interfaces that it implements.
-        sm = getServiceManager(self.context)
-        relevant = [(servicename, interface)
-                    for servicename, interface in sm.getServiceDefinitions()
-                    if interface.isImplementedBy(self.added_object)]
-        if not relevant:
-            return # Not a service, apparently.
-
-        relevant.sort() # Avoid random ordering
-
-        added_url = getPhysicalPathString(self.added_object)
-
-        for servicename, interface in relevant:
-            # Build a configuration object for the service.
-            configure = traverse(self.context, 'configure')
-            container = getAdapter(configure, IZopeContainer)
-            sc = ServiceConfiguration(servicename, added_url, self.context)
-            name = container.setObject("", sc)
-            sc = container[name]
-
-        if len(relevant) == 1:
-            # Redirect to the ServiceConfiguration object
-            url = getPhysicalPathString(sc)
-        else:
-            # Redirect to the "Uses" view (which links to all SC objects)
-            url = added_url + "/@@useConfiguration"
-
-        self.request.response.redirect(url)
+        url = getPhysicalPathString(self.added_object)
+        self.request.response.redirect(url + "/addConfiguration.html")
 
 
 class ConfigurationAdding(Adding):
@@ -177,32 +154,38 @@
             r.append({'key': name, 'view': view})
         return r
 
-class AddServiceConfiguration(BrowserView):
 
-    def __init__(self, *args):
-        super(AddServiceConfiguration, self).__init__(*args)
-        setUpWidgets(self, IConfiguration)
-
-    def services(self):
-        service = getServiceManager(self.context.context)
-        definitions = service.getServiceDefinitions()
-        names = [name for (name, interface) in definitions]
-        names.sort()
-        return names
-
-    def components(self):
-        service_type = self.request['service_type']
-        service = getServiceManager(self.context.context)
-        type = service.getInterfaceFor(service_type)
-        paths = [info['path']
-                 for info in service.queryComponent(type=type)
-                 ]
-        paths.sort()
-        return paths
-
-    def action(self, service_type, component_path):
-        sd = ServiceConfiguration(service_type, component_path,
-                                  self.context.context)
-        sd = self.context.add(sd)
-        getWidgetsDataForContent(self, IConfiguration, sd, strict=False)
-        self.request.response.redirect(self.context.nextURL())
+class AddServiceConfiguration:
+    """A mixin class."""
+
+    def listServiceTypes(self):
+
+        # Collect all defined services interfaces that it implements.
+        sm = getServiceManager(self.context)
+        lst = []
+        for servicename, interface in sm.getServiceDefinitions():
+            if interface.isImplementedBy(self.context):
+                registry = sm.queryConfigurations(servicename)
+                checked = True
+                if registry and registry.active():
+                    checked = False
+                d = {'name': servicename, 'checked': checked}
+                lst.append(d)
+        return lst
+
+    def action(self, name=[], active=[]):
+        path = getPhysicalPathString(self.context)
+        configure = traverse(getWrapperContainer(self.context), 'configure')
+        container = getAdapter(configure, IZopeContainer)
+
+        for nm in name:
+            # XXX Shouldn't hardcode 'configure'
+            sc = ServiceConfiguration(nm, path, self.context)
+            name = container.setObject("", sc)
+            sc = container[name]
+            if nm in active:
+                sc.status = Active
+            else:
+                sc.status = Registered
+
+        self.request.response.redirect("@@useConfiguration.html")


=== Zope3/src/zope/app/browser/services/useconfiguration.pt 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/browser/services/useconfiguration.pt:1.1.2.3	Mon Mar  3 15:05:21 2003
+++ Zope3/src/zope/app/browser/services/useconfiguration.pt	Mon Mar  3 16:33:08 2003
@@ -17,6 +17,8 @@
 	</li>
       </ul>
 
+      <p><a href="addConfiguration.html">Add a configuration for this object</a>
+
     </div>
   </body>
 </html>