SVN: CMF/branches/2.0/C CMFCore.CatalogTool: Added 'cmf_uid' method to IndexableObjectWrapper

"Stefan H. Holek" <[email protected]>
Newsgroups gmane.comp.web.zope.cmf.cvs
Message-ID <[email protected]>
Log message for revision 69317:
  CMFCore.CatalogTool: Added 'cmf_uid' method to IndexableObjectWrapper
  so that CMFUid UIDs are not acquired during indexing.
  (http://www.zope.org/Collectors/CMF/446)
  

Changed:
  U   CMF/branches/2.0/CHANGES.txt
  U   CMF/branches/2.0/CMFCore/CatalogTool.py
  U   CMF/branches/2.0/CMFUid/tests/test_uidhandling.py

-=-
Modified: CMF/branches/2.0/CHANGES.txt
===================================================================
--- CMF/branches/2.0/CHANGES.txt	2006-07-31 16:54:39 UTC (rev 69316)
+++ CMF/branches/2.0/CHANGES.txt	2006-07-31 16:55:52 UTC (rev 69317)
@@ -2,6 +2,10 @@
 
   Bug Fixes
 
+    - CMFCore.CatalogTool: Added 'cmf_uid' method to IndexableObjectWrapper
+      so that CMFUid UIDs are not acquired during indexing.
+      (http://www.zope.org/Collectors/CMF/446)
+
     - CMFCore.PortalContent:  '_guessAliases' may leave type information
       with a default alias of '(Default)';  work around that case.
       (http://www.zope.org/Collectors/CMF/445)

Modified: CMF/branches/2.0/CMFCore/CatalogTool.py
===================================================================
--- CMF/branches/2.0/CMFCore/CatalogTool.py	2006-07-31 16:54:39 UTC (rev 69316)
+++ CMF/branches/2.0/CMFCore/CatalogTool.py	2006-07-31 16:55:52 UTC (rev 69317)
@@ -17,9 +17,11 @@
 
 from AccessControl import ClassSecurityInfo
 from AccessControl.PermissionRole import rolesForPermissionOn
+from Acquisition import aq_base
 from DateTime import DateTime
 from Globals import DTMLFile
 from Globals import InitializeClass
+from Products.PluginIndexes.common import safe_callable
 from Products.ZCatalog.ZCatalog import ZCatalog
 from zope.interface import implements
 from zope.interface import providedBy
@@ -96,7 +98,17 @@
             del allowed['Owner']
         return list(allowed.keys())
 
+    def cmf_uid(self):
+        """
+        Return the CMFUid UID of the object while making sure
+        it is not accidentally acquired.
+        """
+        cmf_uid = getattr(aq_base(self.__ob), 'cmf_uid', '')
+        if safe_callable(cmf_uid):
+            return cmf_uid()
+        return cmf_uid
 
+
 class CatalogTool(UniqueObject, ZCatalog, ActionProviderBase):
 
     """ This is a ZCatalog that filters catalog queries.

Modified: CMF/branches/2.0/CMFUid/tests/test_uidhandling.py
===================================================================
--- CMF/branches/2.0/CMFUid/tests/test_uidhandling.py	2006-07-31 16:54:39 UTC (rev 69316)
+++ CMF/branches/2.0/CMFUid/tests/test_uidhandling.py	2006-07-31 16:55:52 UTC (rev 69317)
@@ -220,7 +220,33 @@
         # IMHO it makes sense here to catch exceptions in general here!
         self.assertRaises(Exception, handler.setUid, dummy, DummyUid())
 
+    def test_UidCataloging(self):
+        handler = self.root.portal_uidhandler
+        catalog = self.root.portal_catalog
+        dummy = self.root.dummy
 
+        uid = handler.register(dummy)
+        brains = catalog(cmf_uid=uid)
+        self.assertEqual(len(brains), 1)
+
+    def test_UidCatalogingDoesNotAcquireUid(self):
+        handler = self.root.portal_uidhandler
+        catalog = self.root.portal_catalog
+        self.root._setObject('folder', DummyFolder('folder'))
+        folder = self.root.folder
+
+        uid = handler.register(folder)
+        brains = catalog(cmf_uid=uid)
+        self.assertEqual(len(brains), 1)
+
+        # Now catalog an unregistered subobject of the folder.
+        # It should not acquire the cmf_uid, obviously.
+        folder._setObject('dummy', DummyContent(id='dummy'))
+        folder.dummy.indexObject()
+        brains = catalog(cmf_uid=uid)
+        self.assertEqual(len(brains), 1)
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(UniqueIdHandlerTests),
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.