[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/Browser - Adding.py:1.11 Contents.py:1.9

Jim Fulton jim@zope.com
Mon, 18 Nov 2002 18:53:29 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv25757/Views/Browser

Modified Files:
	Adding.py Contents.py 
Log Message:
Created an adapter that provides Zope framework services for
containers, including:

  - Context wrapping

  - Event generation

  - Add and delete hooks

Modified the adding and contents views to use the new adapter.

Added interfaces defining add and delete hooks.





=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Adding.py 1.10 => 1.11 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Adding.py:1.10	Mon Nov 18 08:34:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Adding.py	Mon Nov 18 18:52:59 2002
@@ -17,18 +17,18 @@
 """
 
 from Zope.App.OFS.Container.IAdding import IAdding
-from Zope.Proxy.ProxyIntrospection import removeAllProxies
 from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.Publisher.IPublishTraverse import IPublishTraverse
 from Zope.ComponentArchitecture \
-     import getView, getService, createObject, queryFactory, queryView
+     import getView, getService, createObject, \
+            queryFactory, queryView, getAdapter
 from Zope.App.PageTemplate import ViewPageTemplateFile
 from Zope.ContextWrapper import ContextMethod, getbaseobject
 from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.Event import publishEvent
 from Zope.Event.ObjectEvent \
      import ObjectCreatedEvent, ObjectModifiedEvent, ObjectAddedEvent
-
+from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
 class Adding(BrowserView):
 
     __implements__ =  IAdding, IPublishTraverse
@@ -41,12 +41,11 @@
 
     def add(self, content):
         'See Zope.App.OFS.Container.IAdding.IAdding'
-        content = removeAllProxies(content) # XXX We need to think about this
-        name = self.context.setObject(self.contentName, content)
-        content = ContextWrapper(self.context[name], self.context, name=name)
-        publishEvent(self.context, ObjectAddedEvent(content))
-        publishEvent(self.context, ObjectModifiedEvent(self.context))
-        return content
+        container = self.context
+        container = getAdapter(container, IZopeContainer)
+        name = container.setObject(self.contentName, content)
+        return container[name]
+
     
     # See Zope.App.OFS.Container.Views.Browser.IAdding.IAdding
     contentName = None # usually set by Adding traverser


=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py 1.8 => 1.9 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py:1.8	Fri Oct  4 15:55:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Contents.py	Mon Nov 18 18:52:59 2002
@@ -18,11 +18,12 @@
 from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.App.PageTemplate import ViewPageTemplateFile
 from Zope.App.OFS.Container.IContainer import IContainer
-from Zope.ComponentArchitecture import queryView, getView, queryAdapter
+from Zope.ComponentArchitecture \
+     import queryView, getView, queryAdapter,  getAdapter
 from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore
 from Zope.Event import publishEvent
-from Zope.Event.ObjectEvent import ObjectModifiedEvent, ObjectRemovedEvent
 from Zope.Proxy.ContextWrapper import ContextWrapper
+from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
 
 class Contents(BrowserView):
 
@@ -60,24 +61,13 @@
 
     def removeObjects(self, ids):
         """Remove objects specified in a list of object ids"""
+        container = self.context
         for id in ids:
-            self._remove(id)
-
-        publishEvent(self.context, ObjectModifiedEvent(self.context))
+            container = getAdapter(container, IZopeContainer)
+            container.__delitem__(id)
 
         self.request.response.redirect('@@contents.html')
         
-
-    def _remove(self, name):
-        """
-            Remove the object stored under 'name', or raise a KeyError
-            if no such object.
-        """
-        content = ContextWrapper(self.context[name], self.context,
-                                 name=name)
-        del self.context[name]
-        publishEvent(self.context, ObjectRemovedEvent(content))
-
     def listContentInfo(self):
         return map(self._extractContentInfo, self.context.items())