[CMF-checkins] SVN: CMF/trunk/CMFTopic/ - CMFTopic.Topic: Made Topics a tad more useful by subclassing from

Jens Vagelpohl jens at dataflake.org
Thu Aug 18 19:38:09 EDT 2005


Log message for revision 38002:
  - CMFTopic.Topic: Made Topics a tad more useful by subclassing from
    CMFDefault.SkinnedFolder instead of CMFCore.PortalFolder, because
    SkinnedFolder is CatalogAware. Topics now offer useful information
    for Title, Description and SearchableText, so Topic objects can
    be located in the portal by using the standars search facilities.
    (http://www.zope.org/Collectors/CMF/53)
  

Changed:
  U   CMF/trunk/CMFTopic/Topic.py
  U   CMF/trunk/CMFTopic/tests/test_Topic.py

-=-
Modified: CMF/trunk/CMFTopic/Topic.py
===================================================================
--- CMF/trunk/CMFTopic/Topic.py	2005-08-18 23:37:25 UTC (rev 38001)
+++ CMF/trunk/CMFTopic/Topic.py	2005-08-18 23:38:09 UTC (rev 38002)
@@ -19,7 +19,7 @@
 from Acquisition import aq_parent, aq_inner
 from Globals import InitializeClass
 
-from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFDefault.SkinnedFolder import SkinnedFolder
 from Products.CMFCore.utils import getToolByName
 
 from permissions import ListFolderContents
@@ -92,7 +92,7 @@
         REQUEST['RESPONSE'].redirect( 'manage_main' )
 
 
-class Topic( PortalFolder ):
+class Topic( SkinnedFolder ):
 
     """ Topics are 'canned queries'
     
@@ -162,6 +162,8 @@
             self.title = title
         self.description = description
 
+        self.reindexObject()
+
     security.declareProtected(View, 'buildQuery')
     def buildQuery( self ):
 
@@ -274,4 +276,15 @@
 
         return tuple( result )
 
+    #
+    #   Cataloging helper to make finding this item easier
+    #
+    security.declareProtected(View, 'SearchableText')
+    def SearchableText(self):
+        """
+        SeachableText is used for full text seraches of a portal.  It
+        should return a concatenation of all useful text.
+        """
+        return "%s %s" % (self.title, self.description) 
+
 InitializeClass( Topic )

Modified: CMF/trunk/CMFTopic/tests/test_Topic.py
===================================================================
--- CMF/trunk/CMFTopic/tests/test_Topic.py	2005-08-18 23:37:25 UTC (rev 38001)
+++ CMF/trunk/CMFTopic/tests/test_Topic.py	2005-08-18 23:38:09 UTC (rev 38002)
@@ -78,6 +78,8 @@
                     bucket = self._indexes[ index_id ].setdefault( word, [] )
                     bucket.append( rid )
 
+    indexObject = _index
+
     def searchResults( self, REQUEST=None, **kw ):
 
         from sets import Set
@@ -220,13 +222,39 @@
         self.assertEqual( len( query ), 1 )
         self.assertEqual( query['baz'], 'bam' )
 
+    def test_selfIndexing(self):
+        # The Topic object is CatalogAware and should be in the catalog
+        # after it has beeen instantiated.
+        self._initSite()
+        topic = self._makeOne('top')
+
+        # A topic without criteria will return a full catalog search result
+        # set, so we should not have one result, for the Topic object itself.
+        results = topic.queryCatalog()
+
+        self.assertEquals(len(results), 1)
+        self.assertEquals(results[0].getObject().getId(), topic.getId())
+        self.assertEquals(results[0].getObject(), topic)
+
+    def test_searchableText(self):
+        # Test the catalog helper
+        topic = self._makeOne('top')
+        topic.edit(False, title='FOO', description='BAR')
+
+        st = topic.SearchableText()
+        self.failUnless(st.find('BAR') != -1)
+        self.failUnless(st.find('FOO') != -1)
+
     def test_queryCatalog_noop( self ):
 
         self._initSite()
         self._initDocuments( **_DOCUMENTS )
         topic = self._makeOne('top')
 
-        brains = topic.queryCatalog()
+        # Need to filter out the Topic object itself, which is also
+        # CatalogAware and will index itself after instantiation.
+        brains = [ x for x in topic.queryCatalog()
+                      if x.getObject().getId() != 'top' ]
 
         self.assertEqual( len( brains ), len( _DOCUMENTS ) )
 
@@ -265,7 +293,11 @@
         self._initDocuments( **_DOCUMENTS )
         topic = self._makeOne('top')
 
-        brains = topic.synContentValues()
+        #brains = topic.synContentValues()
+        # Need to filter out the Topic object itself, which is also
+        # CatalogAware and will index itself after instantiation.
+        brains = [ x for x in topic.synContentValues()
+                      if x.getObject().getId() != 'top' ]
 
         self.assertEqual( len( brains ), len( _DOCUMENTS ) )
 



More information about the CMF-checkins mailing list