[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - connection.py:1.9 connections.pt:1.9

Guido van Rossum guido@python.org
Wed, 30 Apr 2003 12:26:11 -0400


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

Modified Files:
	connection.py connections.pt 
Log Message:
Add delete etc. functionality to connection mananger.

=== Zope3/src/zope/app/browser/services/connection.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/services/connection.py:1.8	Thu Apr 24 14:02:12 2003
+++ Zope3/src/zope/app/browser/services/connection.py	Wed Apr 30 12:26:09 2003
@@ -17,14 +17,85 @@
 """
 
 from zope.app.browser.services.configuration import AddComponentConfiguration
+from zope.app.interfaces.container import IZopeContainer
 from zope.app.interfaces.services.configuration import IUseConfiguration
 from zope.component import getAdapter, getServiceManager, getView
 from zope.publisher.browser import BrowserView
-from zope.app.traversing import traverse
+from zope.app.interfaces.services.configuration import Unregistered, Registered
+from zope.app.traversing import traverse, getPath, getParent, objectName
 
 class Connections(BrowserView):
 
     # self.context is the local connection service
+
+    def update(self):
+        """Possibly deactivate or delete one or more connections.
+
+        In that case, issue a message.
+        """
+        todo = self.request.get("selected")
+        doDeactivate = self.request.get("Deactivate")
+        doDelete = self.request.get("Delete")
+        if not todo:
+            if doDeactivate or doDelete:
+                return "Please select at least one checkbox"
+            return None
+        if doDeactivate:
+            return self._deactivate(todo)
+        if doDelete:
+            return self._delete(todo)
+
+    def _deactivate(self, todo):
+        done = []
+        for name in todo:
+            registry = self.context.queryConfigurations(name)
+            obj = registry.active()
+            if obj is not None:
+                obj.status = Registered
+                done.append(name)
+        if done:
+            return "Deactivated: " + ", ".join(done)
+        else:
+            return "None of the checked connections were active"
+
+    def _delete(self, todo):
+        errors = []
+        for name in todo:
+            registry = self.context.queryConfigurations(name)
+            assert registry
+            if registry.active() is not None:
+                errors.append(name)
+                continue
+        if errors:
+            return ("Can't delete active connection%s: %s; "
+                    "use the Deactivate button to deactivate" %
+                    (len(errors) != 1 and "s" or "", ", ".join(errors)))
+
+        # 1) Delete the registrations
+        connections = {}
+        for name in todo:
+            registry = self.context.queryConfigurations(name)
+            assert registry
+            assert registry.active() is None # Phase error
+            for info in registry.info():
+                conf = info['configuration']
+                obj = conf.getComponent()
+                path = getPath(obj)
+                connections[path] = obj
+                conf.status = Unregistered
+                parent = getParent(conf)
+                name = objectName(conf)
+                container = getAdapter(parent, IZopeContainer)
+                del container[name]
+
+        # 2) Delete the connection objects
+        for path, obj in connections.items():
+            parent = getParent(obj)
+            name = objectName(obj)
+            container = getAdapter(parent, IZopeContainer)
+            del container[name]
+
+        return "Deleted: %s" % ", ".join(todo)
 
     def getConfigs(self):
         L = []


=== Zope3/src/zope/app/browser/services/connections.pt 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/services/connections.pt:1.8	Mon Apr 28 17:35:29 2003
+++ Zope3/src/zope/app/browser/services/connections.pt	Wed Apr 30 12:26:09 2003
@@ -2,14 +2,25 @@
 
 <div metal:fill-slot="body"
      i18n:domain="zope"
-     tal:define="configs view/getConfigs"
+     tal:define="message view/update; configs view/getConfigs"
      >
 
 <h2 i18n:translate="">Connections registered in this connection service:</h2>
 
-<table tal:condition="configs">
-  <tbody>
+      <div class="message" tal:condition="message">
+         <span tal:replace="message">view/update message here</span>
+         <br><br><i><a href="">(click to clear message)</a></i>
+      </div>
+
+<p tal:condition="not:configs">None</p>
+
+<form method="POST" action="index.html" tal:condition="configs">
+
+  <table>
     <tr tal:repeat="config configs">
+      <td><input type="checkbox" name="selected:list"
+                 tal:attributes="value config/name" />
+      </td>
       <td>
 
         <a href="."
@@ -36,8 +47,13 @@
            >(change registration)</a>
       </td>
     </tr>
-  </tbody>
-</table>
+  </table>
+
+  <input type="submit" name="Deactivate" value="Deactivate" />
+  <input type="submit" name="Delete" value="Delete" />
+  <input type="submit" name="Refresh" value="Refresh" />
+
+</form>
 
 <p><a href="../../default/AddConnection">Add a connection to this
 connection service</a></p>