2009-05-11 18:52:16 +02:00
|
|
|
"""Catalog indexers, using plone.indexer. These will populate standard catalog
|
|
|
|
indexes with values based on the IComment interface.
|
|
|
|
|
|
|
|
Also provide event handlers to actually catalog the comments.
|
|
|
|
"""
|
|
|
|
|
2009-06-01 11:59:07 +02:00
|
|
|
from string import split, join
|
|
|
|
|
2009-06-02 01:17:13 +02:00
|
|
|
from DateTime import DateTime
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
from Products.CMFCore.interfaces import IContentish
|
|
|
|
|
|
|
|
from Products.ZCatalog.interfaces import IZCatalog
|
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
from plone.indexer import indexer
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
from plone.app.discussion.interfaces import IConversation, IComment
|
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
|
2009-06-01 11:59:07 +02:00
|
|
|
MAX_DESCRIPTION=25
|
|
|
|
|
2009-07-01 22:57:55 +02:00
|
|
|
# Conversation Indexers
|
|
|
|
|
|
|
|
from plone.indexer.interfaces import IIndexer
|
|
|
|
|
|
|
|
@indexer(IContentish, IZCatalog)
|
|
|
|
def total_comments(object):
|
|
|
|
conversation = IConversation(object)
|
|
|
|
return conversation.total_comments
|
|
|
|
|
|
|
|
@indexer(IContentish, IZCatalog)
|
|
|
|
def last_comment_date(object):
|
|
|
|
conversation = IConversation(object)
|
|
|
|
return conversation.last_comment_date
|
|
|
|
|
|
|
|
@indexer(IContentish, IZCatalog)
|
|
|
|
def commentators(object):
|
|
|
|
conversation = IConversation(object)
|
2009-07-02 19:50:20 +02:00
|
|
|
return tuple(set(conversation.commentators.keys()))
|
2009-07-01 22:57:55 +02:00
|
|
|
|
|
|
|
# Comment Indexers
|
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
@indexer(IComment)
|
2009-06-02 01:45:49 +02:00
|
|
|
def title(object):
|
2009-05-31 19:55:46 +02:00
|
|
|
return object.title
|
|
|
|
|
2009-06-02 01:29:09 +02:00
|
|
|
@indexer(IComment)
|
2009-06-02 01:45:49 +02:00
|
|
|
def creator(object):
|
2009-06-02 01:29:09 +02:00
|
|
|
return object.creator
|
|
|
|
|
2009-05-31 21:07:35 +02:00
|
|
|
@indexer(IComment)
|
2009-06-02 01:45:49 +02:00
|
|
|
def description(object):
|
2009-07-01 12:01:37 +02:00
|
|
|
# Return the first 25 words of the comment text and append ' [...]'
|
|
|
|
text = join(object.text.split()[:MAX_DESCRIPTION])
|
|
|
|
if len(object.text.split()) > 25:
|
|
|
|
text += " [...]"
|
|
|
|
return text
|
2009-05-31 21:07:35 +02:00
|
|
|
|
2009-05-31 19:55:46 +02:00
|
|
|
@indexer(IComment)
|
2009-06-02 01:45:49 +02:00
|
|
|
def searchable_text(object):
|
2009-05-31 19:55:46 +02:00
|
|
|
return object.title, object.text
|
|
|
|
|
2009-06-02 01:17:13 +02:00
|
|
|
@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)
|