[Zope3-checkins] CVS: Zope3/src/zope/app/services - folder.py:1.4
Jim Fulton
jim@zope.com
Sun, 23 Mar 2003 13:04:57 -0500
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv12947/src/zope/app/services
Modified Files:
folder.py
Log Message:
Added code to prevent deleting the last configuration manager from a site-management folder
=== Zope3/src/zope/app/services/folder.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/folder.py:1.3 Sun Mar 23 12:20:48 2003
+++ Zope3/src/zope/app/services/folder.py Sun Mar 23 13:04:26 2003
@@ -28,6 +28,7 @@
from zope.app.traversing import getPath
from zope.proxy.context import ContextMethod, ContextWrapper
from zope.app.interfaces.services.configuration import IConfigurationManager
+from zope.app.interfaces.services.folder import NoConfigurationManagerError
class SiteManagementFolder(BTreeContainer):
__implements__ = ISiteManagementFolder
@@ -36,6 +37,20 @@
super(SiteManagementFolder, self).__init__()
self.setObject('configure', ConfigurationManager())
+
+ def __delitem__(self, name):
+ """Delete an item, but not if it's the last configuration manager
+ """
+
+ item = self[name]
+ if IConfigurationManager.isImplementedBy(item):
+ # Check to make sure it's not the last one
+ if len([i for i in self.values()
+ if IConfigurationManager.isImplementedBy(i)]) < 2:
+ raise NoConfigurationManagerError(
+ "Can't delete the last configuration manager")
+ BTreeContainer.__delitem__(self, name)
+
def getConfigurationManager(self):
"""Get a configuration manager
"""
@@ -47,7 +62,8 @@
# We found one. Get it in context
return ContextWrapper(item, self, name=name)
else:
- raise SystemError("Couldn't find an configuration manager")
+ raise NoConfigurationManagerError(
+ "Couldn't find an configuration manager")
getConfigurationManager = ContextMethod(getConfigurationManager)