[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - cache.py:1.7 caches.pt:1.7

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


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

Modified Files:
	cache.py caches.pt 
Log Message:
Added Deactivate and Delete buttons to listing of registered caches.


=== Zope3/src/zope/app/browser/services/cache.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/cache.py:1.6	Mon Apr 28 11:04:38 2003
+++ Zope3/src/zope/app/browser/services/cache.py	Wed Apr 30 11:30:41 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 Caches(BrowserView):
 
     # self.context is the local caching service
+
+    def update(self):
+        """Possibly delete one or more caches.
+
+        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 caches 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 cache%s: %s; "
+                    "use the Deactivate button to deactivate" %
+                    (len(errors) != 1 and "s" or "", ", ".join(errors)))
+
+        # 1) Delete the registrations
+        caches = {}
+        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)
+                caches[path] = obj
+                conf.status = Unregistered
+                parent = getParent(conf)
+                name = objectName(conf)
+                container = getAdapter(parent, IZopeContainer)
+                del container[name]
+
+        # 2) Delete the cache objects
+        for path, obj in caches.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/caches.pt 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/caches.pt:1.6	Mon Apr 28 17:35:29 2003
+++ Zope3/src/zope/app/browser/services/caches.pt	Wed Apr 30 11:30:41 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="">Caches registered in this cache 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/AddCache">Add a cache to this cache
 service</a></p>