[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - configure.zcml:1.47 service.py:1.20

Guido van Rossum guido@python.org
Mon, 28 Apr 2003 16:42:58 -0400


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

Modified Files:
	configure.zcml service.py 
Log Message:
Add a new "Add Utility" menu, so you can create new utilities directly
from the utility service.


=== Zope3/src/zope/app/browser/services/configure.zcml 1.46 => 1.47 ===
--- Zope3/src/zope/app/browser/services/configure.zcml:1.46	Mon Apr 28 16:18:56 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Mon Apr 28 16:42:27 2003
@@ -663,6 +663,20 @@
 
   </view>
 
+<!-- "Add Utility" menu -->
+
+  <view
+    name="AddUtility"
+     for="zope.app.interfaces.services.folder.ISiteManagementFolder"
+     permission="zope.ManageServices"
+     class="zope.app.browser.services.service.UtilityAdding">
+
+    <page name="index.html"  attribute="index"  />
+    <page name="action.html" attribute="action" />
+
+  </view>
+    
+
 <!-- Translation Service Views -->
 <include package=".translation" />
 


=== Zope3/src/zope/app/browser/services/service.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/browser/services/service.py:1.19	Thu Apr 24 13:22:12 2003
+++ Zope3/src/zope/app/browser/services/service.py	Mon Apr 28 16:42:27 2003
@@ -25,6 +25,7 @@
 from zope.app.interfaces.services.configuration import Unregistered
 from zope.app.interfaces.services.service import ILocalService
 from zope.app.interfaces.services.service import IServiceManager
+from zope.app.interfaces.services.utility import ILocalUtility
 from zope.app.pagetemplate import ViewPageTemplateFile
 from zope.app.services.folder import SiteManagementFolder
 from zope.app.services.service import ServiceConfiguration
@@ -89,6 +90,18 @@
             raise TypeError("%s is not a local service" % content)
 
         return ContextSuper(ServiceAdding, self).add(content)
+
+class UtilityAdding(ComponentAdding):
+    """Adding subclass used for adding utilities."""
+
+    menu_id = "add_utility"
+
+    def add(self, content):
+        # Override so as to check the type of the new object.
+        # XXX This wants to be generalized!
+        if not ILocalUtility.isImplementedBy(content):
+            raise TypeError("%s is not a local utility" % content)
+        return ContextSuper(UtilityAdding, self).add(content)
 
 
 class AddServiceConfiguration(BrowserView):