[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - service.py:1.6.2.1
Tim Peters
tim.one@comcast.net
Tue, 25 Feb 2003 16:28:24 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv10218/src/zope/app/browser/services
Modified Files:
Tag: use-config-branch
service.py
Log Message:
When you add a service, you're now automatically taken to its
configuration page (instead of needing to plow thru several other
pages first, finding the same service repeatedly). This doesn't
feel squeaky clean (to Tim), but appears to have the virtue of
working.
Also taught such unit tests as proved to need it about
IAttributeUseConfigurable, and yesterday's UseConfiguration adapter.
=== Zope3/src/zope/app/browser/services/service.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/browser/services/service.py:1.6 Fri Feb 21 09:53:34 2003
+++ Zope3/src/zope/app/browser/services/service.py Tue Feb 25 16:27:54 2003
@@ -16,7 +16,7 @@
$Id$
"""
-from zope.app.browser.container.adding import Adding as ContentAdding
+from zope.app.browser.container.adding import Adding
from zope.component import getView, getAdapter
from zope.proxy.context import ContextWrapper, ContextSuper
from zope.app.interfaces.container import IZopeContainer
@@ -25,15 +25,20 @@
from zope.app.services.service import ServiceConfiguration
from zope.app.interfaces.services.configuration import IConfiguration
from zope.app.form.utility import setUpWidgets, getWidgetsDataForContent
+from zope.app.traversing import traverse, getPhysicalPathString
__metaclass__ = type
-class ComponentAdding(ContentAdding):
+class ComponentAdding(Adding):
"""Adding component for components
"""
menu_id = "add_component"
+ def add(self, content):
+ self.added_object = ContextSuper(ComponentAdding, self).add(content)
+ return self.added_object
+
def action(self, type_name, id):
if not id:
# Generate an id from the type name
@@ -46,9 +51,30 @@
while ("%s-%s" % (id, i)) in self.context:
i=i+1
id = "%s-%s" % (id, i)
- return ContextSuper(ComponentAdding, self).action(type_name, id)
+ ContextSuper(ComponentAdding, self).action(type_name, id)
+
+ # See whether the added object is a service; if not, just return.
+ sm = getServiceManager(self.context)
+ defs = sm.getServiceDefinitions()
+ for servicename, interface in defs:
+ if interface.isImplementedBy(self.added_object):
+ break
+ 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)
+
+ # Build URL for config object and redirect to it.
+ url = getPhysicalPathString(config) + "/" + name
+ self.request.response.redirect(url)
+
-class ConfigurationAdding(ContentAdding):
+class ConfigurationAdding(Adding):
"""Adding component for configuration
"""