[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - configureutility.pt:1.1 utilities.pt:1.1 configure.zcml:1.3 useconfiguration.py:1.3

Fred L. Drake, Jr. fred@zope.com
Thu, 3 Apr 2003 17:06:03 -0500


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

Modified Files:
	configure.zcml useconfiguration.py 
Added Files:
	configureutility.pt utilities.pt 
Log Message:
Added configuration user-interface for the local utility service.

=== Added File Zope3/src/zope/app/browser/services/utility/configureutility.pt ===
<html metal:use-macro="context/@@standard_macros/page">

<div metal:fill-slot="body"
     i18n:domain="zope"
     >

<h2 i18n:translate="" tal:condition="request/name">
  Utility configurations for interface
  <span tal:replace="request/interface" i18n:name="interface"/>
  with name
  <span tal:replace="request/name" i18n:name="utility_name" />
</h2>
<h2 i18n:translate="" tal:condition="not:request/name">
  Utility configurations for interface
  <span tal:replace="request/interface" i18n:name="interface"/>
</h2>

<form method="POST"
      action="."
      tal:attributes="action request/URL"
      tal:define="form view/update"
      >
  <input type="hidden"
         name="interface"
         tal:attributes="value request/interface"
         />
  <input type="hidden"
         name="name"
         tal:attributes="value request/name"
         />

  <div tal:replace="structure form" />

  <input type="submit"
         name="submit_update"
         value="Update"
         i18n:attributes="value form_update"
         />

</form>

</div>

</html>


=== Added File Zope3/src/zope/app/browser/services/utility/utilities.pt ===
<html metal:use-macro="context/@@standard_macros/page">

<div metal:fill-slot="body"
     i18n:domain="zope"
     tal:define="configs view/getConfigs"
     >

<h2 i18n:translate="">Configured utilities in this utility service:</h2>

<table tal:condition="configs">
  <tbody>
    <tr tal:repeat="config configs">
      <td>

        <a href="."
           tal:condition="config/url"
           tal:attributes="href config/url"
           >
          <span tal:replace="config/interface" />
          <span tal:condition="config/name" i18n:translate="">
            named <span tal:replace="config/name" i18n:name="utility_name" />
          </span>
        </a>

        <span tal:condition="not:config/url">
          <span tal:replace="config/interface" />
          <span tal:condition="config/name" i18n:translate="">
            named <span tal:replace="config/name" i18n:name="utility_name" />
          </span>
          <span i18n:translate="">(inactive)</span>
        </span>

      </td>
      <td>
        <a href="."
           tal:attributes="href config/configurl"
           i18n:translate=""
           >(configure)</a>
      </td>
    </tr>
  </tbody>
</table>

</div>

</html>


=== Zope3/src/zope/app/browser/services/utility/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/services/utility/configure.zcml:1.2	Fri Mar 21 16:02:18 2003
+++ Zope3/src/zope/app/browser/services/utility/configure.zcml	Thu Apr  3 17:05:32 2003
@@ -17,6 +17,23 @@
       menu="zmi_views" title="Configurations"
       />
 
+  <page
+      for="zope.app.interfaces.services.utility.ILocalUtilityService"
+      name="utilities.html"
+      template="utilities.pt"
+      class=".useconfiguration.Utilities"
+      permission="zope.ManageServices"
+      menu="zmi_views"
+      title="Utilities"
+      />
+
+  <page
+      for="zope.app.interfaces.services.utility.ILocalUtilityService"
+      name="configureutility.html"
+      template="configureutility.pt"
+      class=".useconfiguration.ConfigureUtility"
+      permission="zope.ManageServices"
+      />
 
   <addform
       label="New Utility Configuration"


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.2	Fri Mar 21 16:02:18 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py	Thu Apr  3 17:05:32 2003
@@ -21,7 +21,7 @@
 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.component import getAdapter, getServiceManager, getView
 from zope.interface.implements import flattenInterfaces
 from zope.proxy.introspection import removeAllProxies
 from zope.publisher.browser import BrowserView
@@ -85,3 +85,39 @@
     """
 
     interface = CustomWidget(UtilityInterfaceWidget)
+
+
+class Utilities(BrowserView):
+    def getConfigs(self):
+        L = []
+        for iface, name, cr in self.context.getRegisteredMatching():
+            active = cr.active()
+            ifname = _interface_name(iface)
+            d = {"interface": ifname,
+                 "name": name,
+                 "url": "",
+                 "configurl": ("@@configureutility.html?interface=%s&name=%s"
+                               % (ifname, name)),
+                 }
+            if active is not None:
+                d["url"] = str(getView(active.getComponent(),
+                                       "absolute_url",
+                                       self.request))
+            L.append((ifname, name, d))
+        L.sort()
+        return [d for ifname, name, d in L]
+
+
+class ConfigureUtility(BrowserView):
+    def update(self):
+        sm = getServiceManager(self.context)
+        iface = sm.resolve(self.request['interface'])
+        name = self.request['name']
+        cr = self.context.queryConfigurations(name, iface)
+        form = getView(cr, "ChangeConfigurations", self.request)
+        form.update()
+        return form
+
+
+def _interface_name(iface):
+    return "%s.%s" % (iface.__module__, iface.__name__)