[Zope3-checkins] SVN: Zope3/trunk/ contents.html no longer breaks when no IAdding is available.

Shane Hathaway shane at zope.com
Fri Nov 12 19:01:16 EST 2004


Log message for revision 28448:
  contents.html no longer breaks when no IAdding is available.
  
  This was pretty involved:
  
  - IAdding did not fully document the methods expected by contents.html, 
  and BasicAdding did not implement the required methods.  Therefore, I
  combined Adding and BasicAdding into a single class called Adding and 
  added the missing methods to the interface.
  
  - nameAllowed and namesAccepted apparently served the same purpose and 
  did exactly the same thing, so I changed all references to namesAccepted 
  to nameAllowed (nameAllowed won because a unit test for it exists.)
  
  - Added ZCML that takes effect only when running functional tests.
  
  - Added a functional test that verifies contents.html can display the 
  contents of a read-only container without breaking.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  A   Zope3/trunk/package-includes/zope.app.container.browser-ftesting.zcml
  U   Zope3/trunk/src/zope/app/container/browser/add.pt
  U   Zope3/trunk/src/zope/app/container/browser/adding.py
  U   Zope3/trunk/src/zope/app/container/browser/commontasks.pt
  U   Zope3/trunk/src/zope/app/container/browser/contents.pt
  U   Zope3/trunk/src/zope/app/container/browser/contents.py
  A   Zope3/trunk/src/zope/app/container/browser/ftests/configure.zcml
  U   Zope3/trunk/src/zope/app/container/browser/ftests/test_contents.py
  U   Zope3/trunk/src/zope/app/container/browser/tests/test_adding.py
  U   Zope3/trunk/src/zope/app/container/interfaces.py
  U   Zope3/trunk/src/zope/app/schema/browser/schema_add.pt
  U   Zope3/trunk/src/zope/app/workflow/stateful/browser/add.pt
  U   Zope3/trunk/src/zwiki/browser/add.pt

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/doc/CHANGES.txt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -192,6 +192,8 @@
 
     Bug Fixes
 
+      - contents.html no longer breaks when no IAdding is available.
+
       - Fixed the page that reports "system errors", errors that
         represent a failure of the system, rather than the user, to set
         the response status to 500.

Added: Zope3/trunk/package-includes/zope.app.container.browser-ftesting.zcml
===================================================================
--- Zope3/trunk/package-includes/zope.app.container.browser-ftesting.zcml	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/package-includes/zope.app.container.browser-ftesting.zcml	2004-11-13 00:01:16 UTC (rev 28448)
@@ -0,0 +1 @@
+<include package="zope.app.container.browser.ftests" />

Modified: Zope3/trunk/src/zope/app/container/browser/add.pt
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/add.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/add.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -33,7 +33,7 @@
       <tr>
         <td><br /></td>
         <td><input type="text" name="id"
-                   tal:condition="view/namesAccepted"
+                   tal:condition="view/nameAllowed"
                    tal:attributes="value request/id | nothing" />
             <input type="submit" name="add" value=" Add "
                    i18n:attributes="value add-button" />

Modified: Zope3/trunk/src/zope/app/container/browser/adding.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/adding.py	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/adding.py	2004-11-13 00:01:16 UTC (rev 28448)
@@ -43,7 +43,7 @@
 from zope.app.publisher.browser.menu import getMenu
 from zope.app.publisher.interfaces.browser import AddMenu
 
-class BasicAdding(BrowserView):
+class Adding(BrowserView):
     implements(IAdding, IPublishTraverse)
 
     def add(self, content):
@@ -111,7 +111,7 @@
 
         factory = zapi.queryUtility(IFactory, name)
         if factory is None:
-            return super(BasicAdding, self).publishTraverse(request, name)
+            return super(Adding, self).publishTraverse(request, name)
 
         return factory
 
@@ -159,16 +159,10 @@
         self.add(content)
         self.request.response.redirect(self.nextURL())
 
-    def namesAccepted(self):
-        return not IContainerNamesContainer.providedBy(self.context)
-
     def nameAllowed(self):
         """Return whether names can be input by the user."""
         return not IContainerNamesContainer.providedBy(self.context)
 
-
-class Adding(BasicAdding):
-
     menu_id = None
     index = ViewPageTemplateFile("add.pt")
 
@@ -209,6 +203,8 @@
                return True
        return False
 
+
 class ContentAdding(Adding):
 
     menu_id = "add_content"
+

Modified: Zope3/trunk/src/zope/app/container/browser/commontasks.pt
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/commontasks.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/commontasks.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -2,9 +2,9 @@
            condition="addingInfo" i18n:domain="zope">
 
   <tal:block repeat="info addingInfo"
-	define="namesRequired context/@@+/namesAccepted">
+	define="namesRequired context/@@+/nameAllowed">
     <div tal:define="oddrow repeat/info/odd;
-		     namesRequired context/@@+/namesAccepted;
+		     namesRequired context/@@+/nameAllowed;
         has_custom_add_view python:'has_custom_add_view' in info"
       	tal:attributes="class python:oddrow and 'content even' or 'content odd'"
 	class="even">

Modified: Zope3/trunk/src/zope/app/container/browser/contents.pt
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/contents.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/contents.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -39,7 +39,8 @@
 
         <tbody>
 
-        <tr tal:define="names_required context/@@+/namesAccepted"
+        <metal:block tal:condition="view/hasAdding">
+        <tr tal:define="names_required context/@@+/nameAllowed"
 	    tal:condition="python:names_required and request.has_key('type_name')">
           <td></td>
           <td><input name="new_value" id="focusid" value="" /></td>
@@ -47,6 +48,7 @@
           <td></td>
           <td></td>
         </tr>
+        </metal:block>
 
         <metal:block tal:define="supportsRename view/supportsRename"
                      tal:repeat="item container_contents">
@@ -112,8 +114,7 @@
         </tbody>
       </table>
 
-      <div tal:condition="view/normalButtons" 
-	   tal:define="addingInfo context/@@+/addingInfo|nothing">
+      <div tal:condition="view/normalButtons">
 
         <input type="submit" name="container_rename_button" value="Rename"
                i18n:attributes="value container-rename-button"
@@ -137,9 +138,13 @@
                i18n:domain="zope"
                />
 
-	<div tal:condition="context/@@+/isSingleMenuItem" tal:omit-tag="" 
-	     tal:define="has_custom_add_view context/@@+/hasCustomAddView; 
-			 names_required context/@@+/namesAccepted">
+        <div tal:condition="view/hasAdding" tal:omit-tag="">
+        <div tal:omit-tag="" 
+             tal:define="adding nocall:context/@@+;
+                         addingInfo adding/addingInfo;
+                         has_custom_add_view adding/hasCustomAddView; 
+                         names_required adding/nameAllowed"
+             tal:condition="adding/isSingleMenuItem">
           <input type="submit" name="container_add_button" value="Add"
 	         i18n:attributes="value add-button"
                  i18n:domain="zope"
@@ -152,7 +157,8 @@
                value=""
                tal:attributes="value python:addingInfo[0]['action']" 
                />
-	</div>
+        </div>
+        </div>
 
       </div>
 

Modified: Zope3/trunk/src/zope/app/container/browser/contents.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/contents.py	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/contents.py	2004-11-13 00:01:16 UTC (rev 28448)
@@ -33,7 +33,7 @@
 from zope.app.copypastemove.interfaces import IObjectMover
 from zope.app.copypastemove import rename
 
-from zope.app.container.browser.adding import BasicAdding
+from zope.app.container.browser.adding import Adding
 from zope.app.container.interfaces import IContainer
 from zope.app.container.interfaces import IContainerNamesContainer
 
@@ -216,6 +216,11 @@
         dc = IDCDescriptiveProperties(item)
         dc.title = new
 
+    def hasAdding(self):
+        """Returns true if an adding view is available."""
+        adding = zapi.queryView(self.context, "+", self.request)
+        return (adding is not None)
+
     def addObject(self):
         request = self.request
         if IContainerNamesContainer.providedBy(self.context):
@@ -225,7 +230,7 @@
 
         adding = zapi.queryView(self.context, "+", request)
         if adding is None:
-            adding = BasicAdding(self.context, request)
+            adding = Adding(self.context, request)
         else:
             # Set up context so that the adding can build a url
             # if the type name names a view.

Added: Zope3/trunk/src/zope/app/container/browser/ftests/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/ftests/configure.zcml	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/ftests/configure.zcml	2004-11-13 00:01:16 UTC (rev 28448)
@@ -0,0 +1,16 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:browser="http://namespaces.zope.org/browser">
+
+  <content class=".test_contents.ReadOnlyContainer">
+    <require
+        permission="zope.ManageContent"
+        interface="zope.app.container.interfaces.IReadContainer"
+        />
+  </content>
+
+  <browser:containerViews
+      for="zope.app.container.interfaces.IReadContainer"
+      contents="zope.ManageContent" />
+
+</configure>

Modified: Zope3/trunk/src/zope/app/container/browser/ftests/test_contents.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/ftests/test_contents.py	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/ftests/test_contents.py	2004-11-13 00:01:16 UTC (rev 28448)
@@ -25,6 +25,7 @@
 
 from zope.app import zapi
 from zope.app.annotation.interfaces import IAttributeAnnotatable
+from zope.app.container.interfaces import IReadContainer, IContained
 from zope.app.dublincore.interfaces import IZopeDublinCore
 
 from zope.app.tests.functional import FunctionalDocFileSuite
@@ -32,6 +33,22 @@
 class File(Persistent):
     implements(IAttributeAnnotatable)
 
+class ReadOnlyContainer(Persistent):
+    implements(IReadContainer, IContained)
+    __parent__ = __name__ = None
+
+    def __init__(self): self.data = {}
+    def keys(self): return self.data.keys()
+    def __getitem__(self, key): return self.data[key]
+    def get(self, key, default=None): return self.data.get(key, default)
+    def __iter__(self): return iter(self.data)
+    def values(self): return self.data.values()
+    def __len__(self): return len(self.data)
+    def items(self): return self.data.items()
+    def __contains__(self, key): return key in self.data
+    def has_key(self, key): return self.data.has_key(key)
+
+
 class Test(BrowserTestCase):
 
     def test_inplace_add(self):
@@ -259,7 +276,14 @@
         root._p_jar.sync()
         self.assertEqual(tuple(root.keys()), ('bar', 'bar-2'))
 
+    def test_readonly_display(self):
+        root = self.getRootFolder()
+        root['foo'] = ReadOnlyContainer()
+        get_transaction().commit()
+        response = self.publish('/foo/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
 
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(Test))

Modified: Zope3/trunk/src/zope/app/container/browser/tests/test_adding.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/tests/test_adding.py	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/browser/tests/test_adding.py	2004-11-13 00:01:16 UTC (rev 28448)
@@ -137,7 +137,7 @@
         container = Container()
         adding = Adding(container, TestRequest())
         adding.nextURL = lambda: '.'
-        adding.namesAccepted = lambda: True
+        adding.nameAllowed = lambda: True
 
         # we can't use a private factory:
         self.assertRaises(ForbiddenAttribute, 
@@ -158,7 +158,7 @@
             type_name='***', id='bar')
 
         # alternative add - id is provided internally instead of from user
-        adding.namesAccepted = lambda: False
+        adding.nameAllowed = lambda: False
         adding.contentName = 'baz'
         adding.action(type_name='foo')
         self.assert_('baz' in container)

Modified: Zope3/trunk/src/zope/app/container/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/container/interfaces.py	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/container/interfaces.py	2004-11-13 00:01:16 UTC (rev 28448)
@@ -215,7 +215,20 @@
 
     def nameAllowed():
         """Return whether names can be input by the user."""
+
+    def addingInfo():
+        """Returns add menu data as a sequence of mappings.
+
+        Each mapping contains 'action', 'title', and possibly other keys.
+
+        The result is sorted by title.
+        """
+
+    def isSingleMenuItem():
+        "Return whether there is single menu item or not."
     
+    def hasCustomAddView():
+       "This should be called only if there is `singleMenuItem` else return 0"
 
 
 class INameChooser(Interface):

Modified: Zope3/trunk/src/zope/app/schema/browser/schema_add.pt
===================================================================
--- Zope3/trunk/src/zope/app/schema/browser/schema_add.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/schema/browser/schema_add.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -34,7 +34,7 @@
         <td><br /></td>
         <td>
             <input type="text" name="id"
-                   tal:condition="view/namesAccepted"
+                   tal:condition="view/nameAllowed"
                    tal:attributes="value request/id | nothing" />
             <input type="submit" value=" Add " 
                    i18n:attributes="value add-button" />

Modified: Zope3/trunk/src/zope/app/workflow/stateful/browser/add.pt
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/browser/add.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zope/app/workflow/stateful/browser/add.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -59,7 +59,7 @@
         <td><br /></td>
         <td>
             <input type="text" name="id"
-                   tal:condition="view/namesAccepted"
+                   tal:condition="view/nameAllowed"
                    tal:attributes="value request/id | nothing"
             />
             <input type="submit" value="Add" 

Modified: Zope3/trunk/src/zwiki/browser/add.pt
===================================================================
--- Zope3/trunk/src/zwiki/browser/add.pt	2004-11-12 23:42:43 UTC (rev 28447)
+++ Zope3/trunk/src/zwiki/browser/add.pt	2004-11-13 00:01:16 UTC (rev 28448)
@@ -59,7 +59,7 @@
     <td><br/></td>
     <td>
         <input type="text" name="id"
-               tal:condition="view/namesAccepted"
+               tal:condition="view/nameAllowed"
 	       tal:attributes="value request/id | nothing"
         />
         <input type="submit" value=" Add " />



More information about the Zope3-Checkins mailing list