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

Stefan H. Holek stefan at epy.co.at
Mon Jul 31 12:53:09 EDT 2006


Log message for revision 69315:
  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/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFCore/CatalogTool.py
  U   CMF/branches/1.5/CMFUid/tests/test_uidhandling.py

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2006-07-31 16:21:00 UTC (rev 69314)
+++ CMF/branches/1.5/CHANGES.txt	2006-07-31 16:53:08 UTC (rev 69315)
@@ -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/1.5/CMFCore/CatalogTool.py
===================================================================
--- CMF/branches/1.5/CMFCore/CatalogTool.py	2006-07-31 16:21:00 UTC (rev 69314)
+++ CMF/branches/1.5/CMFCore/CatalogTool.py	2006-07-31 16:53:08 UTC (rev 69315)
@@ -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 Products.ZCTextIndex.HTMLSplitter import HTMLWordSplitter
 from Products.ZCTextIndex.Lexicon import CaseNormalizer
@@ -75,7 +77,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/1.5/CMFUid/tests/test_uidhandling.py
===================================================================
--- CMF/branches/1.5/CMFUid/tests/test_uidhandling.py	2006-07-31 16:21:00 UTC (rev 69314)
+++ CMF/branches/1.5/CMFUid/tests/test_uidhandling.py	2006-07-31 16:53:08 UTC (rev 69315)
@@ -230,8 +230,34 @@
         # throws lets check for all exceptions! 
         # 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 TestSuite((
         makeSuite(UniqueIdHandlerTests),



More information about the CMF-checkins mailing list