[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/Browser - Adding.py:1.2 configure.zcml:1.1 add.pt:1.3

Jim Fulton jim@zope.com
Thu, 20 Jun 2002 16:00:51 -0400


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

Modified Files:
	add.pt 
Added Files:
	Adding.py configure.zcml 
Log Message:

Gary and Jim implemented most of:
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/AddMenuProposalAndEndOfZmiNamespace

A lot of clean up is needed, including:

- Implementation additional add menus, for example for services.

- Ripping out old unused implementation.





=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/Adding.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+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
+
+class Adding(BrowserView):
+
+    __implements__ =  IAdding, IPublishTraverse
+
+    menu_id = "add_content"
+
+    ############################################################
+    # Implementation methods for interface
+    # IAdding.py
+
+    def add(self, content):
+        'See Zope.App.OFS.Container.IAdding.IAdding'
+        content = removeAllProxies(content) # XXX We need to think about this
+        return self.context.setObject(self.contentName, content)
+    
+    # See Zope.App.OFS.Container.Views.Browser.IAdding.IAdding
+    contentName=None # usually set by Adding traverser
+
+    def nextURL(self):
+        'See Zope.App.OFS.Container.IAdding.IAdding'
+        return str(getView(self.context, "absolute_url", self.request))
+
+    ######################################
+    # from: Zope.ComponentArchitecture.IPresentation.IPresentation
+
+    # See Zope.ComponentArchitecture.IPresentation.IPresentation
+    request = None # set in BrowserView.__init__
+
+    ######################################
+    # from: Zope.ComponentArchitecture.IContextDependent.IContextDependent
+
+    # See Zope.ComponentArchitecture.IContextDependent.IContextDependent
+    context = None # set in BrowserView.__init__
+
+    ######################################
+    # from: Zope.Publisher.IPublishTraverse.IPublishTraverse
+
+    def publishTraverse(self, request, name):
+        if '=' in name:            
+            view_name, content_name =name.split("=",1)
+            if content_name:
+                self.contentName = content_name
+
+            return getView(self, view_name, request)
+
+        view = queryView(self, name, request)
+        if view is not None:
+            return view
+
+        factory = queryFactory(self.context, name)
+        if factory is None:
+            return super(Adding, self).publishTraverse(request, name)
+
+        return factory
+
+    
+    #
+    ############################################################
+
+    def addingInfo(self):
+        """Return menu data"""
+
+        menu_service = getService(self.context, "BrowserMenu")
+        return menu_service.getMenu(self.menu_id, self, self.request)
+
+    def action(self, type_name, id):
+        if queryView(self, type_name, self.request) is not None:
+            self.request.response.redirect(type_name)
+
+        if not id:
+            raise ValueError("You must specify an id")
+
+        self.contentName = id
+        
+        content = createObject(self, type_name)
+        self.add(content)
+        self.request.response.redirect(self.nextURL())
+
+
+


=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
   >

   <browser:menu id="add_content" 
                 title="Menu of objects to be added to content containers"
                 />

   <browser:view
       for="Zope.App.OFS.Container.IContentContainer."
       name="create"  
       factory=".Adding."
       permission="Zope.ManageContent"
       >
       <browser:page name="index.html" template="add.pt" />
       <browser:page name="action.html" attribute="action" />
   </browser:view>

</zopeConfigure>
       


=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/add.pt 1.2 => 1.3 ===
 <head>
 <style metal:fill-slot="headers" type="text/css">
-.TypeListing {
-    width: 100%;
-}
 
 .Selector {
     width: 10px;
@@ -27,10 +24,10 @@
 
 <div metal:fill-slot="body">
 
-<form action="@@add.html" method="POST">
+<form action="action.html" method="POST">
 <table class="TypeListing">
 
-  <caption>Add Content To Folder</caption>
+  <caption>Add Content</caption>
 
     <tr>
       <td class="Selector"><br /></td>
@@ -42,23 +39,18 @@
       **   'id'    : the ID of the addable type
       **   'title' : the title of the addable type
       **   'description'  : the description of the addable type
-      **   'icon'  : the absolute URL of the icon, for the addable type
-                     (may be None)
       -->
-    <tbody tal:repeat="info view/listAddableInfo">
+    <tbody tal:repeat="info view/addingInfo">
 
     <tr>
 
       <td class="Selector">
         <input type="radio" name="type_name"
-               tal:attributes="value info/id; id info/id" />
+               tal:attributes="value info/action; id info/action" />
       </td>
 
       <td class="TypeName">
-        <label tal:attributes="for info/id">
-          <img alt="Folder" src="../../ZMI/www/folder_icon.gif"
-               tal:condition="info/icon"
-               tal:attributes="src info/icon" />
+        <label tal:attributes="for info/action">
           <span tal:replace="info/title">Folder</span>
         </label>
       </td>