[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - service.py:1.6.2.2
Guido van Rossum
guido@python.org
Thu, 27 Feb 2003 12:25:24 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv8106/src/zope/app/browser/services
Modified Files:
Tag: use-config-branch
service.py
Log Message:
Make the UI deal with objects that implement more than one service.
- If the created object is not a service, use the default next URL.
- Otherwise, create a service configuration object for each service
it implements. Then:
- If there's exactly one of those, redirect to the default view of
that service configuration object.
- Else, redirect to the service object's "Uses" tab (hardcoded as
"@@useConfiguration") from which the user can select each
configuration object in turn. (That tab needs work but that's a
separate task.)
=== Zope3/src/zope/app/browser/services/service.py 1.6.2.1 => 1.6.2.2 ===
--- Zope3/src/zope/app/browser/services/service.py:1.6.2.1 Tue Feb 25 16:27:54 2003
+++ Zope3/src/zope/app/browser/services/service.py Thu Feb 27 12:25:23 2003
@@ -26,6 +26,7 @@
from zope.app.interfaces.services.configuration import IConfiguration
from zope.app.form.utility import setUpWidgets, getWidgetsDataForContent
from zope.app.traversing import traverse, getPhysicalPathString
+from zope.component.interfaces import IService
__metaclass__ = type
@@ -36,6 +37,7 @@
menu_id = "add_component"
def add(self, content):
+ # Override so as to save a reference to the added object
self.added_object = ContextSuper(ComponentAdding, self).add(content)
return self.added_object
@@ -51,26 +53,41 @@
while ("%s-%s" % (id, i)) in self.context:
i=i+1
id = "%s-%s" % (id, i)
+
+ # Call the superclass action() method.
+ # As a side effect, self.added_object is set by add() above.
ContextSuper(ComponentAdding, self).action(type_name, id)
- # See whether the added object is a service; if not, just return.
+ if not IService.isImplementedBy(self.added_object):
+ return # It's not a service
+
+ # Collect all defined services interfaces that it implements.
sm = getServiceManager(self.context)
- defs = sm.getServiceDefinitions()
- for servicename, interface in defs:
- if interface.isImplementedBy(self.added_object):
- break
+ relevant = [(servicename, interface)
+ for servicename, interface in sm.getServiceDefinitions()
+ if interface.isImplementedBy(self.added_object)]
+ if not relevant:
+ return # Not a service, apparently.
+
+ relevant.sort() # Avoid random ordering
+
+ added_url = getPhysicalPathString(self.added_object)
+
+ for servicename, interface in relevant:
+ # Build a configuration object for the service.
+ configure = traverse(self.context, 'configure')
+ container = getAdapter(configure, IZopeContainer)
+ sc = ServiceConfiguration(servicename, added_url)
+ name = container.setObject("", sc)
+ sc = container[name]
+
+ if len(relevant) == 1:
+ # Redirect to the ServiceConfiguration object
+ url = getPhysicalPathString(sc)
else:
- return
-
- # Build a configuration object for the service.
- config = traverse(self.context, 'configure')
- container = getAdapter(config, IZopeContainer)
- sc = ServiceConfiguration(servicename,
- getPhysicalPathString(self.added_object))
- name = container.setObject("", sc)
+ # Redirect to the "Uses" view (which links to all SC objects)
+ url = added_url + "/@@useConfiguration"
- # Build URL for config object and redirect to it.
- url = getPhysicalPathString(config) + "/" + name
self.request.response.redirect(url)