Indexes for created and modified added.
svn path=/plone.app.discussion/trunk/; revision=27257
This commit is contained in:
parent
69334f6000
commit
04bed35357
@ -6,6 +6,8 @@ Also provide event handlers to actually catalog the comments.
|
|||||||
|
|
||||||
from string import split, join
|
from string import split, join
|
||||||
|
|
||||||
|
from DateTime import DateTime
|
||||||
|
|
||||||
from plone.indexer import indexer
|
from plone.indexer import indexer
|
||||||
|
|
||||||
from plone.app.discussion.interfaces import IComment
|
from plone.app.discussion.interfaces import IComment
|
||||||
@ -25,3 +27,28 @@ def comment_description(object):
|
|||||||
def comment_searchable_text(object):
|
def comment_searchable_text(object):
|
||||||
return object.title, object.text
|
return object.title, object.text
|
||||||
|
|
||||||
|
@indexer(IComment)
|
||||||
|
def effective(object):
|
||||||
|
# the catalog index needs Zope DateTime instead of Python datetime
|
||||||
|
# Todo!!!
|
||||||
|
return DateTime
|
||||||
|
|
||||||
|
@indexer(IComment)
|
||||||
|
def created(object):
|
||||||
|
# the catalog index needs Zope DateTime instead of Python datetime
|
||||||
|
return DateTime(object.creation_date.year,
|
||||||
|
object.creation_date.month,
|
||||||
|
object.creation_date.day,
|
||||||
|
object.creation_date.hour,
|
||||||
|
object.creation_date.minute,
|
||||||
|
object.creation_date.second)
|
||||||
|
|
||||||
|
@indexer(IComment)
|
||||||
|
def modified(object):
|
||||||
|
# the catalog index needs Zope DateTime instead of Python datetime
|
||||||
|
return DateTime(object.modification_date.year,
|
||||||
|
object.modification_date.month,
|
||||||
|
object.modification_date.day,
|
||||||
|
object.modification_date.hour,
|
||||||
|
object.modification_date.minute,
|
||||||
|
object.modification_date.second)
|
||||||
|
@ -61,5 +61,9 @@
|
|||||||
<adapter name="Title" factory=".catalog.comment_title" />
|
<adapter name="Title" factory=".catalog.comment_title" />
|
||||||
<adapter name="Description" factory=".catalog.comment_description" />
|
<adapter name="Description" factory=".catalog.comment_description" />
|
||||||
<adapter name="SearchableText" factory=".catalog.comment_searchable_text" />
|
<adapter name="SearchableText" factory=".catalog.comment_searchable_text" />
|
||||||
|
<adapter name="effective" factory=".catalog.effective" />
|
||||||
|
<adapter name="created" factory=".catalog.created" />
|
||||||
|
<adapter name="modified" factory=".catalog.modified" />
|
||||||
|
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from DateTime import DateTime
|
||||||
|
|
||||||
from zope.component import createObject
|
from zope.component import createObject
|
||||||
|
|
||||||
from Products.PloneTestCase.ptc import PloneTestCase
|
from Products.PloneTestCase.ptc import PloneTestCase
|
||||||
@ -12,7 +15,7 @@ from plone.indexer.delegate import DelegatingIndexerFactory
|
|||||||
|
|
||||||
from zope.component import provideAdapter
|
from zope.component import provideAdapter
|
||||||
|
|
||||||
from plone.app.discussion.catalog import comment_title, comment_description, comment_searchable_text
|
from plone.app.discussion import catalog
|
||||||
|
|
||||||
class IndexersTest(PloneTestCase):
|
class IndexersTest(PloneTestCase):
|
||||||
|
|
||||||
@ -23,7 +26,7 @@ class IndexersTest(PloneTestCase):
|
|||||||
self.loginAsPortalOwner()
|
self.loginAsPortalOwner()
|
||||||
typetool = self.portal.portal_types
|
typetool = self.portal.portal_types
|
||||||
typetool.constructContent('Document', self.portal, 'doc1')
|
typetool.constructContent('Document', self.portal, 'doc1')
|
||||||
provideAdapter(comment_title, name='title')
|
provideAdapter(catalog.comment_title, name='title')
|
||||||
|
|
||||||
def test_comment_title(self):
|
def test_comment_title(self):
|
||||||
|
|
||||||
@ -43,8 +46,8 @@ class IndexersTest(PloneTestCase):
|
|||||||
|
|
||||||
new_id = conversation.addComment(comment)
|
new_id = conversation.addComment(comment)
|
||||||
|
|
||||||
self.assertEquals(comment_title(comment)(), 'Comment 1')
|
self.assertEquals(catalog.comment_title(comment)(), 'Comment 1')
|
||||||
self.assert_(isinstance(comment_title, DelegatingIndexerFactory))
|
self.assert_(isinstance(catalog.comment_title, DelegatingIndexerFactory))
|
||||||
|
|
||||||
def test_comment_description(self):
|
def test_comment_description(self):
|
||||||
# Create a 50 word comment and make sure the description returns
|
# Create a 50 word comment and make sure the description returns
|
||||||
@ -66,12 +69,33 @@ class IndexersTest(PloneTestCase):
|
|||||||
|
|
||||||
new_id = conversation.addComment(comment)
|
new_id = conversation.addComment(comment)
|
||||||
|
|
||||||
self.assertEquals(comment_description(comment)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At...')
|
self.assertEquals(catalog.comment_description(comment)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At...')
|
||||||
self.assert_(isinstance(comment_description, DelegatingIndexerFactory))
|
self.assert_(isinstance(catalog.comment_description, DelegatingIndexerFactory))
|
||||||
|
|
||||||
def test_dates(self):
|
def test_dates(self):
|
||||||
# created, modified, effective etc
|
# Test if created, modified, effective etc. are set correctly
|
||||||
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'
|
||||||
|
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
||||||
|
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
|
||||||
|
|
||||||
|
new_id = conversation.addComment(comment)
|
||||||
|
|
||||||
|
# Check the indexes
|
||||||
|
self.assertEquals(catalog.created(comment)(), DateTime(2006, 9, 17, 14, 18, 12))
|
||||||
|
self.assertEquals(catalog.modified(comment)(), DateTime(2008, 3, 12, 7, 32, 52))
|
||||||
|
|
||||||
def test_searchable_text(self):
|
def test_searchable_text(self):
|
||||||
# Create a conversation. In this case we doesn't assign it to an
|
# Create a conversation. In this case we doesn't assign it to an
|
||||||
@ -90,8 +114,8 @@ class IndexersTest(PloneTestCase):
|
|||||||
|
|
||||||
new_id = conversation.addComment(comment)
|
new_id = conversation.addComment(comment)
|
||||||
|
|
||||||
self.assertEquals(comment_searchable_text(comment)(), ('Comment 1', 'Comment text'))
|
self.assertEquals(catalog.comment_searchable_text(comment)(), ('Comment 1', 'Comment text'))
|
||||||
self.assert_(isinstance(comment_searchable_text, DelegatingIndexerFactory))
|
self.assert_(isinstance(catalog.comment_searchable_text, DelegatingIndexerFactory))
|
||||||
|
|
||||||
def test_creator(self):
|
def test_creator(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user