[Checkins] SVN: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/ Make broken root apps deletable.

Uli Fouquet uli at gnufix.de
Sun Aug 26 23:46:57 EDT 2007


Log message for revision 79293:
  Make broken root apps deletable.

Changed:
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/admin/objectinfo.txt
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py

-=-
Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/objectinfo.txt
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/admin/objectinfo.txt	2007-08-26 22:45:40 UTC (rev 79292)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/admin/objectinfo.txt	2007-08-27 03:46:56 UTC (rev 79293)
@@ -334,7 +334,7 @@
 directly provided ones.
 
   >>> root_info.getProvidedInterfaces()
-  (<InterfaceClass zope.app.folder.interfaces.IFolder>, <InterfaceClass persistent.interfaces.IPersistent>, <InterfaceClass zope.app.component.interfaces.IPossibleSite>, <InterfaceClass zope.app.container.interfaces.IContained>)
+  (<InterfaceClass zope.app.folder.interfaces.IFolder>, <InterfaceClass persistent.interfaces.IPersistent>, <InterfaceClass zope.location.interfaces.IPossibleSite>, <InterfaceClass zope.app.container.interfaces.IContained>)
 
   >>> sweethome_info.getProvidedInterfaces()
   (<InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>, <InterfaceClass zope.app.container.interfaces.IContainer>, <InterfaceClass zope.app.container.interfaces.IContained>, <InterfaceClass persistent.interfaces.IPersistent>)

Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py	2007-08-26 22:45:40 UTC (rev 79292)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py	2007-08-27 03:46:56 UTC (rev 79293)
@@ -28,6 +28,7 @@
 from grok.admin.utilities import getPathLinksForDottedName, getParentURL
 
 from ZODB.broken import Broken
+from BTrees.OOBTree import OOBTree
 
 import zope.component
 from zope.interface import Interface
@@ -47,6 +48,7 @@
 from zope.app.folder.interfaces import IRootFolder
 from zope.app.security.interfaces import ILogout, IAuthentication
 from zope.app.security.interfaces import IUnauthenticatedPrincipal
+from zope.exceptions import DuplicationError
 from zope.proxy import removeAllProxies
 from zope.tal.taldefs import attrEscape
 
@@ -56,10 +58,6 @@
 grok.context(IRootFolder)
 grok.define_permission('grok.ManageApplications')
 
-class Sample(grok.Application, grok.Container):
-    pass
-
-
 class Add(grok.View):
     """Add an application.
     """
@@ -77,8 +75,13 @@
             return
         app = zope.component.getUtility(grok.interfaces.IApplication,
                                         name=application)
-        self.context[name] = app()
-        self.flash(u'Added %s `%s`.' % (application, name))
+        try:
+            self.context[name] = app()
+            self.flash(u'Added %s `%s`.' % (application, name))
+        except DuplicationError:
+            self.flash(
+                u'Name `%s` already in use. Please choose another name.' % (
+                name,))
         self.redirect(self.url(self.context))
 
 
@@ -92,23 +95,34 @@
         if items is None:
             self.redirect(self.url(self.context))
             return
+        msg = u''
         if not isinstance(items, list):
             items = [items]
         for name in items:
             try:
                 del self.context[name]
+                msg = (u'%sApplication `%s` was successfully '
+                       u'deleted.\n' % (msg, name))
             except AttributeError:
-                # object is broken and has to be handled special.
-                #self.context[name].__parent__ = self.context
-                #self.context[name] = object()
-                #self.context._setOb(name, None)
-                #self.context.__setitem__(name, None)
+                # Object is broken.. Try it the hard way...
+                # TODO: Try to repair before deleting.
                 obj = self.context[name]
-                #obj = None
-                #del obj
-                del self.context[name]
-                #get_transaction.commit()
-            self.flash(u'Application %s was successfully deleted.' % (name,))
+                if not hasattr(self.context, 'data'):
+                    msg = (
+                        u'%sCould not delete application `%s`: no '
+                        u'`data` attribute found.\n' % (msg, name))
+                    continue
+                if not isinstance(self.context.data, OOBTree):
+                    msg = (
+                        u'%sCould not delete application `%s`: no '
+                        u'`data` is not a BTree.\n' % (msg, name))
+                    continue
+                self.context.data.pop(name)
+                self.context.data._p_changed = True
+                msg = (u'%sBroken application `%s` was successfully '
+                       u'deleted.\n' % (msg, name))
+
+        self.flash(msg)
         self.redirect(self.url(self.context))
 
 
@@ -327,8 +341,11 @@
 
 
 class Applications(GAIAView):
-    """View for application management."""
+    """View for application management.
 
+    TODO: Handle broken objects, which are not in root.
+    """
+
     grok.name('applications')
     grok.require('grok.ManageApplications')
 



More information about the Checkins mailing list