[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - __init__.py:1.2 configure.zcml:1.2 useconfiguration.pt:1.2 useconfiguration.py:1.2

Jim Fulton jim@zope.com
Fri, 21 Mar 2003 16:02:49 -0500


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

Added Files:
	__init__.py configure.zcml useconfiguration.pt 
	useconfiguration.py 
Log Message:
Added a partial utility service implementation.

This *still* needs tests. Yes, I'm breaking the rules. But some folks 
are waiting on this.  Tests will come soon.


=== Zope3/src/zope/app/browser/services/utility/__init__.py 1.1 => 1.2 ===
--- /dev/null	Fri Mar 21 16:02:49 2003
+++ Zope3/src/zope/app/browser/services/utility/__init__.py	Fri Mar 21 16:02:18 2003
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/services/utility/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Fri Mar 21 16:02:49 2003
+++ Zope3/src/zope/app/browser/services/utility/configure.zcml	Fri Mar 21 16:02:18 2003
@@ -0,0 +1,43 @@
+<zopeConfigure xmlns='http://namespaces.zope.org/browser'>
+
+  <menuItem
+      for="zope.app.interfaces.container.IAdding"
+      menu="add_service"
+      action="zope.app.services.UtilityService"
+      title="Utility Service"
+      permission="zope.ManageServices"
+      />
+
+  <page
+      for="zope.app.interfaces.services.utility.ILocalUtility"
+      name="useConfiguration.html"
+      template="useconfiguration.pt"
+      class=".useconfiguration.UseConfiguration"
+      permission="zope.ManageServices"
+      menu="zmi_views" title="Configurations"
+      />
+
+
+  <addform
+      label="New Utility Configuration"
+      for="zope.app.interfaces.services.utility.ILocalUtility"
+      name="addConfiguration.html"
+      schema="zope.app.interfaces.services.utility.IUtilityConfiguration"
+      class=".useconfiguration.AddConfiguration"
+      permission="zope.ManageServices"
+      content_factory="zope.app.services.utility.UtilityConfiguration"
+      arguments="name interface componentPath"
+      set_after_add="status"
+      fields="name interface componentPath permission status"
+      />
+
+  <editform
+      name="index.html"
+      menu="zmi_views" title="Edit"
+      schema="zope.app.interfaces.services.utility.IUtilityConfiguration"
+      label="Utility Configuration"
+      permission="zope.ManageServices"
+      fields="name interface componentPath permission status"
+      />
+
+</zopeConfigure>


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.pt 1.1 => 1.2 ===
--- /dev/null	Fri Mar 21 16:02:49 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.pt	Fri Mar 21 16:02:18 2003
@@ -0,0 +1,27 @@
+<html metal:use-macro="context/@@standard_macros/page">
+<body>
+  <div metal:fill-slot="body">
+
+    <p>Configurations for this utility:</p>
+
+    <ul>
+
+      <li tal:repeat="use view/uses">
+
+	<a href="."
+	   tal:attributes="href use/url">
+	  <span tal:replace="use/interface">IFoo</span>
+	  <span tal:condition="use/name">
+	    named <span tal:replace="use/name" />
+	  </span>
+	</a>
+	(<span tal:replace="use/status">Active</span>)
+
+      </li>
+    </ul>
+
+    <p><a href="addConfiguration.html">Add a configuration for this utility</a>
+
+  </div>
+</body>
+</html>


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.1 => 1.2 ===
--- /dev/null	Fri Mar 21 16:02:49 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py	Fri Mar 21 16:02:18 2003
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Use-Configuration view for utilities.
+
+$Id$
+"""
+
+from zope.app.browser.component.interfacewidget import InterfaceWidget
+from zope.app.browser.services.configuration import AddComponentConfiguration
+from zope.app.form.widget import CustomWidget
+from zope.app.interfaces.services.configuration import IUseConfiguration
+from zope.app.traversing import traverse
+from zope.component import getAdapter, getView
+from zope.interface.implements import flattenInterfaces
+from zope.proxy.introspection import removeAllProxies
+from zope.publisher.browser import BrowserView
+
+class UseConfiguration(BrowserView):
+    """View for displaying the configurations for a utility.
+    """
+
+    def uses(self):
+        """Get a sequence of configuration summaries
+        """
+        component = self.context
+        useconfig = getAdapter(component, IUseConfiguration)
+        result = []
+        for path in useconfig.usages():
+            config = traverse(component, path)
+            url = getView(config, 'absolute_url', self.request)
+            result.append({'name': config.name,
+                           'interface': config.interface.__name__,
+                           'path': path,
+                           'url': url(),
+                           'status': config.status,
+                           })
+        return result
+        
+
+class UtilityInterfaceWidget(InterfaceWidget):
+    """Custom widget to select an interface from the component's interfaces.
+    """
+
+    def __call__(self):
+        field = self.context
+        component = field.context
+        # XXX Have to remove proxies because flattenInterfaces
+        #     doesn't work with proxies.
+        bare = removeAllProxies(component)
+        # Compute the list of interfaces that the component implements
+        interfaces = [
+            interface
+            for interface in flattenInterfaces(bare.__implements__)
+            if list(interface) # Does the interface define any names
+            ]
+        result = ['\n<select name="%s">' % self.name]
+        for interface in interfaces:
+            result.append('  <option value="%s.%s">%s</option>' %
+                          (interface.__module__, interface.__name__,
+                           interface.__name__))
+        result.append('</select>')
+        return '\n'.join(result)
+        
+
+class AddConfiguration(AddComponentConfiguration):
+    """View for adding a utility configuration.
+
+
+    We could just use AddComponentConfiguration, except that we need a
+    custom interface widget.
+
+    This is a view on a local utility, configured by an <addform>
+    directive.
+    """
+
+    interface = CustomWidget(UtilityInterfaceWidget)