[CMF-checkins] SVN: CMF/branches/1.5/C - CMFTopic.Topic: Made
Topics a tad more useful by subclassing from
Jens Vagelpohl
jens at dataflake.org
Thu Aug 18 19:37:25 EDT 2005
Log message for revision 38001:
- 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)
is line, and those below, will be ignored--
M CHANGES.txt
M CMFTopic/tests/test_Topic.py
M CMFTopic/Topic.py
Changed:
U CMF/branches/1.5/CHANGES.txt
U CMF/branches/1.5/CMFTopic/Topic.py
U CMF/branches/1.5/CMFTopic/tests/test_Topic.py
-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt 2005-08-18 22:32:21 UTC (rev 38000)
+++ CMF/branches/1.5/CHANGES.txt 2005-08-18 23:37:25 UTC (rev 38001)
@@ -32,6 +32,15 @@
content_type. It is now preserved, if possible.
(http://www.zope.org/Collectors/CMF/370)
+ Features
+
+ - 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)
+
Others
- CMFCore.PortalFolder._checkId() allows root doted prefixed name
Modified: CMF/branches/1.5/CMFTopic/Topic.py
===================================================================
--- CMF/branches/1.5/CMFTopic/Topic.py 2005-08-18 22:32:21 UTC (rev 38000)
+++ CMF/branches/1.5/CMFTopic/Topic.py 2005-08-18 23:37:25 UTC (rev 38001)
@@ -19,7 +19,7 @@
from Acquisition import aq_parent, aq_inner, aq_base
from Globals import InitializeClass
-from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFDefault.SkinnedFolder import SkinnedFolder
from Products.CMFCore.utils import _getViewFor
from Products.CMFCore.utils import getToolByName
@@ -93,7 +93,7 @@
REQUEST['RESPONSE'].redirect( 'manage_main' )
-class Topic( PortalFolder ):
+class Topic( SkinnedFolder ):
""" Topics are 'canned queries'
@@ -187,6 +187,8 @@
self.title = title
self.description = description
+ self.reindexObject()
+
security.declareProtected(View, 'buildQuery')
def buildQuery( self ):
@@ -299,4 +301,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/branches/1.5/CMFTopic/tests/test_Topic.py
===================================================================
--- CMF/branches/1.5/CMFTopic/tests/test_Topic.py 2005-08-18 22:32:21 UTC (rev 38000)
+++ CMF/branches/1.5/CMFTopic/tests/test_Topic.py 2005-08-18 23:37:25 UTC (rev 38001)
@@ -81,6 +81,8 @@
bucket = self._indexes[ index_id ].setdefault( word, [] )
bucket.append( rid )
+ indexObject = _index
+
def searchResults( self, REQUEST=None, **kw ):
from sets import Set
@@ -227,13 +229,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 ) )
@@ -272,7 +300,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