[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/ - Add views: The standard INameChooser adapter from Products.Five

Jens Vagelpohl jens at dataflake.org
Sun May 24 06:33:36 EDT 2009


Log message for revision 100330:
  - Add views: The standard INameChooser adapter from Products.Five
    fails with BTreeFolder-based portal folders, so we need our own.
    (https://bugs.launchpad.net/zope-cmf/+bug/377562)
  

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/btreefolder.txt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/configure.zcml
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.py
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.txt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/tests.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt	2009-05-24 09:25:48 UTC (rev 100329)
+++ Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt	2009-05-24 10:33:35 UTC (rev 100330)
@@ -4,6 +4,10 @@
 2.2.0 (unreleased)
 ------------------
 
+- Add views: The standard INameChooser adapter from Products.Five 
+  fails with BTreeFolder-based portal folders, so we need our own.
+  (https://bugs.launchpad.net/zope-cmf/+bug/377562)
+
 - Actions: Utilize the new link_target attribute for the
   final rendered link tag's "target" attribute
   (https://bugs.launchpad.net/zope-cmf/+bug/376951)

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/btreefolder.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/btreefolder.txt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/btreefolder.txt	2009-05-24 10:33:35 UTC (rev 100330)
@@ -0,0 +1,53 @@
+Folder Views
+------------
+
+Set up user.
+
+    >>> uf = app.site.acl_users
+    >>> uf._doAddUser('mgr', 'mgrpw', ['Manager'], [])
+
+Create the browser object we'll be using.
+
+    >>> from Products.Five.testbrowser import Browser
+    >>> browser = Browser()
+    >>> browser.handleErrors = False
+    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+Use the add form without input.
+
+    >>> browser.open('http://localhost/site/++add++CMF BTree Folder')
+    >>> '[[cmf_default][Add [[cmf_default][CMF BTree Folder]]]]' in browser.contents
+    True
+    >>> browser.getControl('[[zope][Add]]').click()
+    >>> '[[zope][There were errors]]' in browser.contents
+    True
+    >>> '[[zope][Required input is missing.]]' in browser.contents
+    True
+
+Use the add form with valid input.
+
+    >>> from StringIO import StringIO
+    >>> browser.open('http://localhost/site/++add++CMF BTree Folder')
+    >>> '[[cmf_default][Add [[cmf_default][CMF BTree Folder]]]]' in browser.contents
+    True
+    >>> browser.getControl(name='form.id').value = 'myFolder'
+    >>> browser.getControl('[[zope][Add]]').click()
+    >>> '[[cmf_default][[[cmf_default][CMF BTree Folder]] added.]]' in browser.contents
+    True
+
+Use the folder contents form without input.
+
+    >>> browser.open('http://localhost/site/myFolder/@@edit.html')
+    >>> '[[cmf_default][Folder Contents: ]]' in browser.contents
+    True
+
+Try to add something to this folder.
+
+    >>> browser.open('http://localhost/site/myFolder/++add++Document')
+    >>> '[[cmf_default][Add [[cmf_default][Document]]]]' in browser.contents
+    True
+    >>> browser.getControl(name='form.id').value = 'myDocument'
+    >>> browser.getControl('[[zope][Add]]').click()
+    >>> '[[cmf_default][[[cmf_default][Document]] added.]]' in browser.contents
+    True
+


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/btreefolder.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/configure.zcml
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/configure.zcml	2009-05-24 09:25:48 UTC (rev 100329)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/configure.zcml	2009-05-24 10:33:35 UTC (rev 100330)
@@ -200,4 +200,10 @@
       permission="zope.Public"
       />
 
+  <adapter
+      for="Products.CMFCore.interfaces.IFolderish"
+      factory=".folder.PortalFolderNameChooser"
+      provides="zope.container.interfaces.INameChooser"
+      />
+
 </configure>

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.py	2009-05-24 09:25:48 UTC (rev 100329)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.py	2009-05-24 10:33:35 UTC (rev 100330)
@@ -16,6 +16,7 @@
 """
 
 from DocumentTemplate import sequence  # for sort()
+from Products.Five.browser.adding import ObjectManagerNameChooser
 from Products.PythonScripts.standard import thousands_commas
 from zope.formlib.form import FormFields
 from zope.schema import ASCIILine
@@ -638,3 +639,45 @@
         self.request.RESPONSE.expireCookie('folderfilter', path='/')
         self.request.RESPONSE.expireCookie('show_filter_form', path='/')
         return True, _(u'Filter cleared.')
+
+
+class PortalFolderNameChooser(ObjectManagerNameChooser):
+    """ A name chooser for a portal folder
+
+    Overridden to behave correctly with BTreeFolder-based PortalFolders
+    This class and the adapter registration can be removed as soon as the 
+    Products.Five.adding.ObjectManagerNameChooser works with BTreeFolders.
+    """
+
+    def chooseName(self, name, object):
+        if not name:
+            name = object.__class__.__name__
+        else:
+            try:
+                name = name.encode('ascii')
+            except UnicodeDecodeError:
+                raise UserError, "Id must contain only ASCII characters."
+
+        dot = name.rfind('.')
+        if dot >= 0:
+            suffix = name[dot:]
+            name = name[:dot]
+        else:
+            suffix = ''
+
+        n = name + suffix
+        i = 0
+        while True:
+            i += 1
+            try:
+                self.context._getOb(n)
+            except (AttributeError, KeyError):
+                break
+            n = name + '-' + str(i) + suffix
+
+        # Make sure the name is valid.  We may have started with
+        # something bad.
+        self.checkName(n, object)
+
+        return n
+

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.txt	2009-05-24 09:25:48 UTC (rev 100329)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/folder.txt	2009-05-24 10:33:35 UTC (rev 100330)
@@ -40,3 +40,14 @@
     >>> browser.open('http://localhost/site/myFolder/@@edit.html')
     >>> '[[cmf_default][Folder Contents: ]]' in browser.contents
     True
+
+Try to add something to this folder.
+
+    >>> browser.open('http://localhost/site/myFolder/++add++Document')
+    >>> '[[cmf_default][Add [[cmf_default][Document]]]]' in browser.contents
+    True
+    >>> browser.getControl(name='form.id').value = 'myDocument'
+    >>> browser.getControl('[[zope][Add]]').click()
+    >>> '[[cmf_default][[[cmf_default][Document]] added.]]' in browser.contents
+    True
+

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/tests.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/tests.py	2009-05-24 09:25:48 UTC (rev 100329)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/tests.py	2009-05-24 10:33:35 UTC (rev 100330)
@@ -26,6 +26,9 @@
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocFileSuite('folder_utest.txt',
                                     optionflags=doctest.NORMALIZE_WHITESPACE))
+    s = ZopeTestCase.FunctionalDocFileSuite('btreefolder.txt')
+    s.layer = FunctionalLayer
+    suite.addTest(s)
     s = ZopeTestCase.FunctionalDocFileSuite('folder.txt')
     s.layer = FunctionalLayer
     suite.addTest(s)



More information about the Checkins mailing list