[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - useconfiguration.py:1.6 utilities.pt:1.5
Guido van Rossum
guido@python.org
Wed, 30 Apr 2003 11:15:30 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/services/utility
In directory cvs.zope.org:/tmp/cvs-serv19858/utility
Modified Files:
useconfiguration.py utilities.pt
Log Message:
Added Deactivate and Delete buttons for utilities in the utility
manager UI.
=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.5 Mon Apr 28 12:52:08 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py Wed Apr 30 11:15:30 2003
@@ -19,7 +19,10 @@
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.component import getServiceManager, getView
+from zope.app.interfaces.container import IZopeContainer
+from zope.app.interfaces.services.configuration import Unregistered, Registered
+from zope.app.traversing import getPath, getParent, objectName
+from zope.component import getServiceManager, getView, getAdapter
from zope.interface.implements import flattenInterfaces
from zope.proxy.introspection import removeAllProxies
from zope.publisher.browser import BrowserView
@@ -67,6 +70,81 @@
class Utilities(BrowserView):
# self.context is the local utility service
+
+ def update(self):
+ """Possibly delete one or more utilities.
+
+ In that case, issue a message.
+ """
+ selected = self.request.get("selected")
+ doDeactivate = self.request.get("Deactivate")
+ doDelete = self.request.get("Delete")
+ if not selected:
+ if doDeactivate or doDelete:
+ return "Please select at least one checkbox"
+ return None
+ sm = getServiceManager(self.context)
+ todo = []
+ for key in selected:
+ name, ifacename = key.split(":", 1)
+ iface = sm.resolve(ifacename)
+ todo.append((key, name, iface))
+ if doDeactivate:
+ return self._deactivate(todo)
+ if doDelete:
+ return self._delete(todo)
+
+ def _deactivate(self, todo):
+ done = []
+ for key, name, iface in todo:
+ registry = self.context.queryConfigurations(name, iface)
+ obj = registry.active()
+ if obj is not None:
+ obj.status = Registered
+ done.append(key)
+ if done:
+ return "Deactivated: " + ", ".join(done)
+ else:
+ return "None of the checked utilities were active"
+
+ def _delete(self, todo):
+ errors = []
+ for key, name, iface in todo:
+ registry = self.context.queryConfigurations(name, iface)
+ assert registry
+ if registry.active() is not None:
+ errors.append(key)
+ continue
+ if errors:
+ return ("Can't delete active utilit%s: %s; "
+ "use the Deactivate button to deactivate" %
+ (len(errors) != 1 and "ies" or "y", ", ".join(errors)))
+
+ # 1) Delete the registrations
+ services = {}
+ for key, name, iface in todo:
+ registry = self.context.queryConfigurations(name, iface)
+ assert registry
+ assert registry.active() is None # Phase error
+ for info in registry.info():
+ conf = info['configuration']
+ obj = conf.getComponent()
+ path = getPath(obj)
+ services[path] = obj
+ conf.status = Unregistered
+ parent = getParent(conf)
+ name = objectName(conf)
+ container = getAdapter(parent, IZopeContainer)
+ del container[name]
+
+ # 2) Delete the service objects
+ for path, obj in services.items():
+ parent = getParent(obj)
+ name = objectName(obj)
+ container = getAdapter(parent, IZopeContainer)
+ del container[name]
+
+ return "Deleted: %s" % ", ".join([key for key, name, iface in todo])
def getConfigs(self):
L = []
=== Zope3/src/zope/app/browser/services/utility/utilities.pt 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/services/utility/utilities.pt:1.4 Mon Apr 28 16:42:28 2003
+++ Zope3/src/zope/app/browser/services/utility/utilities.pt Wed Apr 30 11:15:30 2003
@@ -2,14 +2,24 @@
<div metal:fill-slot="body"
i18n:domain="zope"
- tal:define="configs view/getConfigs"
+ tal:define="message view/update; configs view/getConfigs"
>
<h2 i18n:translate="">Utilities registered in this utility 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>
+
+<form method="POST" action="utilities.html">
+
+ <table tal:condition="configs">
<tr tal:repeat="config configs">
+ <td><input type="checkbox" name="selected:list"
+ tal:attributes=
+ "value string:${config/name}:${config/interface}" />
+ </td>
<td>
<a href="."
@@ -39,8 +49,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/AddUtility">Add a utility to this utility
service</a></p>