[CMF-checkins] SVN: CMF/branches/1.5/C CMFCatalogAware: refactoring. Defines now 2 methods, _getCatalogTool()

Julien Anguenot ja at nuxeo.com
Thu Sep 8 08:49:29 EDT 2005


Log message for revision 38390:
  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/branches/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFCore/CMFCatalogAware.py
  U   CMF/branches/1.5/CMFCore/tests/test_CMFCatalogAware.py

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2005-09-08 12:48:30 UTC (rev 38389)
+++ CMF/branches/1.5/CHANGES.txt	2005-09-08 12:49:28 UTC (rev 38390)
@@ -6,6 +6,15 @@
       in the list of events for the day starting at midnight.
       (http://www.zope.org/Collectors/CMF/246)
 
+  Others
+
+    - 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
+
 CMF 1.5.4 (2005/09/04)
 
   Bug Fixes

Modified: CMF/branches/1.5/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/branches/1.5/CMFCore/CMFCatalogAware.py	2005-09-08 12:48:30 UTC (rev 38389)
+++ CMF/branches/1.5/CMFCore/CMFCatalogAware.py	2005-09-08 12:49:28 UTC (rev 38390)
@@ -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:
@@ -123,7 +136,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)
 
@@ -238,7 +251,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/branches/1.5/CMFCore/tests/test_CMFCatalogAware.py
===================================================================
--- CMF/branches/1.5/CMFCore/tests/test_CMFCatalogAware.py	2005-09-08 12:48:30 UTC (rev 38389)
+++ CMF/branches/1.5/CMFCore/tests/test_CMFCatalogAware.py	2005-09-08 12:49:28 UTC (rev 38390)
@@ -29,6 +29,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
 
@@ -106,6 +107,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):
@@ -219,6 +221,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