[CMF-checkins] SVN: CMF/trunk/CMF CMFCore.CatalogTool: Added 'cmf_uid' method to IndexableObjectWrapper

Stefan H. Holek stefan at epy.co.at
Mon Jul 31 12:56:49 EDT 2006


Log message for revision 69318:
  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/trunk/CMFCore/CatalogTool.py
  U   CMF/trunk/CMFUid/tests/test_uidhandling.py

-=-
Modified: CMF/trunk/CMFCore/CatalogTool.py
===================================================================
--- CMF/trunk/CMFCore/CatalogTool.py	2006-07-31 16:55:52 UTC (rev 69317)
+++ CMF/trunk/CMFCore/CatalogTool.py	2006-07-31 16:56:49 UTC (rev 69318)
@@ -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/trunk/CMFUid/tests/test_uidhandling.py
===================================================================
--- CMF/trunk/CMFUid/tests/test_uidhandling.py	2006-07-31 16:55:52 UTC (rev 69317)
+++ CMF/trunk/CMFUid/tests/test_uidhandling.py	2006-07-31 16:56:49 UTC (rev 69318)
@@ -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),



More information about the CMF-checkins mailing list