SVN: CMF/branches/1.6/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 69316:
  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.6/CHANGES.txt
  U   CMF/branches/1.6/CMFCore/CatalogTool.py
  U   CMF/branches/1.6/CMFUid/tests/test_uidhandling.py

-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt	2006-07-31 16:53:08 UTC (rev 69315)
+++ CMF/branches/1.6/CHANGES.txt	2006-07-31 16:54:39 UTC (rev 69316)
@@ -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.6/CMFCore/CatalogTool.py
===================================================================
--- CMF/branches/1.6/CMFCore/CatalogTool.py	2006-07-31 16:53:08 UTC (rev 69315)
+++ CMF/branches/1.6/CMFCore/CatalogTool.py	2006-07-31 16:54:39 UTC (rev 69316)
@@ -19,9 +19,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
@@ -100,7 +102,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.6/CMFUid/tests/test_uidhandling.py
===================================================================
--- CMF/branches/1.6/CMFUid/tests/test_uidhandling.py	2006-07-31 16:53:08 UTC (rev 69315)
+++ CMF/branches/1.6/CMFUid/tests/test_uidhandling.py	2006-07-31 16:54:39 UTC (rev 69316)
@@ -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),
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.