[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - service.py:1.22 services.pt:1.7
Guido van Rossum
guido@python.org
Tue, 29 Apr 2003 17:21:56 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv2649
Modified Files:
service.py services.pt
Log Message:
Implement deletion of services via the service manager.
This is simple and effective but note:
# XXX Jim doesn't like this very much; he thinks it's too much
# magic behind the user's back. OTOH, Guido believes that
# we're providing an abstraction here that hides the
# existence of the folder and its registration manager as
# much as possible, so it's appropriate to clean up when
# deleting a service; if you don't want that, you can
# manipulate the folder explicitly.
=== Zope3/src/zope/app/browser/services/service.py 1.21 => 1.22 ===
--- Zope3/src/zope/app/browser/services/service.py:1.21 Mon Apr 28 17:35:29 2003
+++ Zope3/src/zope/app/browser/services/service.py Tue Apr 29 17:21:55 2003
@@ -29,7 +29,7 @@
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.services.folder import SiteManagementFolder
from zope.app.services.service import ServiceConfiguration
-from zope.app.traversing import traverse, getPath
+from zope.app.traversing import traverse, getPath, getParent, objectName
from zope.component import getServiceManager
from zope.component import getView, getAdapter, queryView
from zope.proxy.context import ContextWrapper, ContextSuper
@@ -151,6 +151,83 @@
class ServiceSummary(BrowserView):
"""A view on the service manager, used by services.pt."""
+
+ def update(self):
+ """Possibly delete one or more services.
+
+ In that case, issue a message.
+ """
+ deletes = self.request.get("delete")
+ doDeactivate = self.request.get("Deactivate")
+ doDelete = self.request.get("Delete")
+ if not deletes:
+ if doDeactivate or doDelete:
+ return "Please select at least one checkbox"
+ return None
+ if doDeactivate:
+ return self._deactivate(deletes)
+ if doDelete:
+ return self._delete(deletes)
+
+ 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 services 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 service%s: %s; "
+ "use the Deactivate button to deactivate" %
+ (len(errors) != 1 and "s" or "", ", ".join(errors)))
+
+ # 1) Delete the registrations
+ services = {}
+ 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)
+ services[path] = obj
+ conf.status = Unregistered
+ parent = getParent(conf)
+ name = objectName(conf)
+ container = getAdapter(parent, IZopeContainer)
+ del container[name]
+
+ # 2) Delete the service objects
+ # XXX Jim doesn't like this very much; he thinks it's too much
+ # magic behind the user's back. OTOH, Guido believes that
+ # we're providing an abstraction here that hides the
+ # existence of the folder and its registration manager as
+ # much as possible, so it's appropriate to clean up when
+ # deleting a service; if you don't want that, you can
+ # manipulate the folder explicitly.
+ print services
+ for path, obj in services.items():
+ parent = getParent(obj)
+ name = objectName(obj)
+ container = getAdapter(parent, IZopeContainer)
+ del container[name]
+
+ return "Deleted: %s" % ", ".join(todo)
def listConfiguredServices(self):
names = list(self.context.listConfigurationNames())
=== Zope3/src/zope/app/browser/services/services.pt 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/services.pt:1.6 Mon Apr 28 12:52:07 2003
+++ Zope3/src/zope/app/browser/services/services.pt Tue Apr 29 17:21:55 2003
@@ -1,14 +1,6 @@
<html metal:use-macro="views/standard_macros/page">
-<tal:block
- metal:fill-slot="headers"
- tal:define="global pagetip string:
-
- To add a service, click on the Add Service link at the
- top of this page.
- "
- />
-
+<tal:block metal:fill-slot="headers" />
<div metal:fill-slot="body">
@@ -16,7 +8,13 @@
Services registered in this service manager
</h2>
- <div tal:define="registries view/listConfiguredServices">
+ <div tal:define="message view/update;
+ registries view/listConfiguredServices">
+
+ <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:registries">No services are registered.</p>
@@ -27,9 +25,12 @@
disabling the service altogether.
</p>
- <table>
- <tbody>
+ <form method="POST" action="services.html">
+
+ <table>
<tr tal:repeat="reg registries">
+ <td><input type="checkbox" name="delete:list"
+ tal:attributes="value reg/name" /></td>
<td>
<a href="(link to the active service)"
tal:condition="reg/url"
@@ -50,8 +51,13 @@
</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/AddService">Add a service to this service
mananger</a></p>
@@ -59,5 +65,7 @@
</div>
</div>
+
</div>
+
</html>