comment_title, comment_text, and comment_searchable_text indexes added.
svn path=/plone.app.discussion/trunk/; revision=27247
This commit is contained in:
		
							parent
							
								
									95405ee48f
								
							
						
					
					
						commit
						5f8acfd805
					
				@ -4,3 +4,19 @@ indexes with values based on the IComment interface.
 | 
				
			|||||||
Also provide event handlers to actually catalog the comments.
 | 
					Also provide event handlers to actually catalog the comments.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from plone.indexer import indexer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from plone.app.discussion.interfaces import IComment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@indexer(IComment)
 | 
				
			||||||
 | 
					def comment_title(object):
 | 
				
			||||||
 | 
					    return object.title
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@indexer(IComment)
 | 
				
			||||||
 | 
					def comment_text(object):
 | 
				
			||||||
 | 
					    return object.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@indexer(IComment)
 | 
				
			||||||
 | 
					def comment_searchable_text(object):
 | 
				
			||||||
 | 
					    return object.title, object.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -57,4 +57,9 @@
 | 
				
			|||||||
        handler=".tool.unindex_object"
 | 
					        handler=".tool.unindex_object"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- adapters for indexes -->
 | 
				
			||||||
 | 
					    <adapter name="title" factory=".catalog.comment_title" />
 | 
				
			||||||
 | 
					    <adapter name="text" factory=".catalog.comment_text" />
 | 
				
			||||||
 | 
					    <adapter name="searchable_text" factory=".catalog.comment_searchable_text" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</configure>
 | 
					</configure>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,24 +1,88 @@
 | 
				
			|||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from zope.component import createObject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from Products.PloneTestCase.ptc import PloneTestCase
 | 
					from Products.PloneTestCase.ptc import PloneTestCase
 | 
				
			||||||
from plone.app.discussion.tests.layer import DiscussionLayer
 | 
					from plone.app.discussion.tests.layer import DiscussionLayer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestIndexers(PloneTestCase):
 | 
					from plone.app.discussion.interfaces import IConversation
 | 
				
			||||||
 | 
					from plone.indexer import indexer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from zope.component import provideAdapter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from plone.app.discussion.catalog import comment_title, comment_text, comment_searchable_text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class IndexersTest(PloneTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    layer = DiscussionLayer
 | 
					    layer = DiscussionLayer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_title(self):
 | 
					    def afterSetUp(self):
 | 
				
			||||||
        pass
 | 
					        # First we need to create some content.
 | 
				
			||||||
 | 
					        self.loginAsPortalOwner()
 | 
				
			||||||
 | 
					        typetool = self.portal.portal_types
 | 
				
			||||||
 | 
					        typetool.constructContent('Document', self.portal, 'doc1')
 | 
				
			||||||
 | 
					        provideAdapter(comment_title, name='title')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_description(self):
 | 
					    def test_comment_title(self):
 | 
				
			||||||
        pass
 | 
					
 | 
				
			||||||
 | 
					        # Create a conversation. In this case we doesn't assign it to an
 | 
				
			||||||
 | 
					        # object, as we just want to check the Conversation object API.
 | 
				
			||||||
 | 
					        conversation = IConversation(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Pretend that we have traversed to the comment by aq wrapping it.
 | 
				
			||||||
 | 
					        conversation = conversation.__of__(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Add a comment. Note: in real life, we always create comments via the factory
 | 
				
			||||||
 | 
					        # to allow different factories to be swapped in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        comment = createObject('plone.Comment')
 | 
				
			||||||
 | 
					        comment.title = 'Comment 1'
 | 
				
			||||||
 | 
					        comment.text = 'Comment text'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        new_id = conversation.addComment(comment)
 | 
				
			||||||
 | 
					        self.assertEquals(comment_title(comment)(), 'Comment 1')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_comment_text(self):
 | 
				
			||||||
 | 
					        # Create a conversation. In this case we doesn't assign it to an
 | 
				
			||||||
 | 
					        # object, as we just want to check the Conversation object API.
 | 
				
			||||||
 | 
					        conversation = IConversation(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Pretend that we have traversed to the comment by aq wrapping it.
 | 
				
			||||||
 | 
					        conversation = conversation.__of__(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Add a comment. Note: in real life, we always create comments via the factory
 | 
				
			||||||
 | 
					        # to allow different factories to be swapped in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        comment = createObject('plone.Comment')
 | 
				
			||||||
 | 
					        comment.title = 'Comment 1'
 | 
				
			||||||
 | 
					        comment.text = 'Comment text'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        new_id = conversation.addComment(comment)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEquals(comment_text(comment)(), 'Comment text')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_dates(self):
 | 
					    def test_dates(self):
 | 
				
			||||||
        # created, modified, effective etc
 | 
					        # created, modified, effective etc
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_searchable_text(self):
 | 
					    def test_searchable_text(self):
 | 
				
			||||||
        pass
 | 
					        # Create a conversation. In this case we doesn't assign it to an
 | 
				
			||||||
 | 
					        # object, as we just want to check the Conversation object API.
 | 
				
			||||||
 | 
					        conversation = IConversation(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Pretend that we have traversed to the comment by aq wrapping it.
 | 
				
			||||||
 | 
					        conversation = conversation.__of__(self.portal.doc1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Add a comment. Note: in real life, we always create comments via the factory
 | 
				
			||||||
 | 
					        # to allow different factories to be swapped in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        comment = createObject('plone.Comment')
 | 
				
			||||||
 | 
					        comment.title = 'Comment 1'
 | 
				
			||||||
 | 
					        comment.text = 'Comment text'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        new_id = conversation.addComment(comment)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEquals(comment_searchable_text(comment)(), ('Comment 1', 'Comment text'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_creator(self):
 | 
					    def test_creator(self):
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								setup.py
									
									
									
									
									
								
							@ -34,6 +34,7 @@ setup(name='plone.app.discussion',
 | 
				
			|||||||
          'zope.annotation',
 | 
					          'zope.annotation',
 | 
				
			||||||
          'zope.event',
 | 
					          'zope.event',
 | 
				
			||||||
          'zope.app.container', # XXX: eventually should change to zope.container
 | 
					          'zope.app.container', # XXX: eventually should change to zope.container
 | 
				
			||||||
 | 
					          'plone.indexer',
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
      entry_points="""
 | 
					      entry_points="""
 | 
				
			||||||
      [z3c.autoinclude.plugin]
 | 
					      [z3c.autoinclude.plugin]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user