[CMF-checkins] SVN: CMF/trunk/CMFCore/ CMFCatalogAware: refactoring. Defines now 2 methods, _getCatalogTool()

Julien Anguenot ja at nuxeo.com
Thu Sep 8 08:55:41 EDT 2005


Log message for revision 38391:
  CMFCatalogAware: refactoring. Defines now 2 methods, _getCatalogTool()
  and _getWorkflowTool(), that are used to find the catalog and workflow
  tool. It's now possible to override these methods using inheritence
  for a given content type to specify another catalog or workflow tool
  the content type can use
  
  

Changed:
  U   CMF/trunk/CMFCore/CMFCatalogAware.py
  U   CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py

-=-
Modified: CMF/trunk/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/CMFCatalogAware.py	2005-09-08 12:49:28 UTC (rev 38390)
+++ CMF/trunk/CMFCore/CMFCatalogAware.py	2005-09-08 12:55:40 UTC (rev 38391)
@@ -37,6 +37,16 @@
 
     security = ClassSecurityInfo()
 
+    # The following methods can be overriden using inheritence so that
+    # it's possible to specifiy another catalog tool or workflow tool
+    # for a given content type
+
+    def _getCatalogTool(self):
+        return getToolByName(self, 'portal_catalog', None)
+
+    def _getWorkflowTool(self):
+        return getToolByName(self, 'portal_workflow', None)
+
     # Cataloging methods
     # ------------------
 
@@ -45,7 +55,7 @@
         """
             Index the object in the portal catalog.
         """
-        catalog = getToolByName(self, 'portal_catalog', None)
+        catalog = self._getCatalogTool()
         if catalog is not None:
             catalog.indexObject(self)
 
@@ -54,7 +64,7 @@
         """
             Unindex the object from the portal catalog.
         """
-        catalog = getToolByName(self, 'portal_catalog', None)
+        catalog = self._getCatalogTool()
         if catalog is not None:
             catalog.unindexObject(self)
 
@@ -72,7 +82,7 @@
             # Update the modification date.
             if hasattr(aq_base(self), 'notifyModified'):
                 self.notifyModified()
-        catalog = getToolByName(self, 'portal_catalog', None)
+        catalog = self._getCatalogTool()
         if catalog is not None:
             catalog.reindexObject(self, idxs=idxs)
 
@@ -88,10 +98,13 @@
         is a useful optimization if the object itself has just been
         fully reindexed, as there's no need to reindex its security twice.
         """
-        catalog = getToolByName(self, 'portal_catalog', None)
+        catalog = self._getCatalogTool()
         if catalog is None:
             return
         path = '/'.join(self.getPhysicalPath())
+
+        # XXX if _getCatalogTool() is overriden we will have to change
+        # this method for the sub-objects.
         for brain in catalog.unrestrictedSearchResults(path=path):
             brain_path = brain.getPath()
             if brain_path == path and skip_self:
@@ -119,7 +132,7 @@
         """
             Notify the workflow that self was just created.
         """
-        wftool = getToolByName(self, 'portal_workflow', None)
+        wftool = self._getWorkflowTool()
         if wftool is not None:
             wftool.notifyCreated(self)
 
@@ -234,7 +247,7 @@
             Tab displaying the current workflows for the content object.
         """
         ob = self
-        wftool = getToolByName(self, 'portal_workflow', None)
+        wftool = self._getWorkflowTool()
         # XXX None ?
         if wftool is not None:
             wf_ids = wftool.getChainFor(ob)

Modified: CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2005-09-08 12:49:28 UTC (rev 38390)
+++ CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2005-09-08 12:55:40 UTC (rev 38391)
@@ -25,6 +25,7 @@
 from OFS.Folder import Folder
 from OFS.SimpleItem import SimpleItem
 from Products.ZCatalog import CatalogBrains
+from Products.CMFCore.WorkflowTool import WorkflowTool
 from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
 from Products.CMFCore.tests.base.testcase import LogInterceptor
 
@@ -102,6 +103,7 @@
         self.root.site = SimpleFolder('site')
         self.site = self.root.site
         self.site._setObject('portal_catalog', DummyCatalog())
+        self.site._setObject('portal_workflow', WorkflowTool())
         self.site.foo = TheClass('foo')
 
     def tearDown(self):
@@ -179,6 +181,14 @@
         self.failIf(missing.notified)
         self.assertEqual( len(self.logged), 1 ) # logging because no raise
 
+    def test_catalog_tool(self):
+        foo = self.site.foo
+        self.assertEqual(foo._getCatalogTool(), self.site.portal_catalog)
+
+    def test_workflow_tool(self):
+        foo = self.site.foo
+        self.assertEqual(foo._getWorkflowTool(), self.site.portal_workflow)
+
     # FIXME: more tests needed
 
 def test_suite():



More information about the CMF-checkins mailing list