2009-05-18 16:16:48 +02:00
|
|
|
"""The portal_discussion tool, usually accessed via
|
|
|
|
getUtility(ICommentingTool). The default implementation delegates to the
|
|
|
|
standard portal_catalog for indexing comments.
|
|
|
|
|
|
|
|
BBB support for the old portal_discussion is provided in the bbb package.
|
|
|
|
"""
|
|
|
|
|
2009-05-16 17:05:22 +02:00
|
|
|
from zope import interface
|
2010-07-12 15:47:53 +02:00
|
|
|
from zope.component import queryUtility
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
from interfaces import ICommentingTool, IComment
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
from Products.CMFCore.utils import UniqueObject, getToolByName
|
|
|
|
from OFS.SimpleItem import SimpleItem
|
|
|
|
|
|
|
|
class CommentingTool(UniqueObject, SimpleItem):
|
|
|
|
|
2009-05-16 17:05:22 +02:00
|
|
|
interface.implements(ICommentingTool)
|
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
meta_type = 'plone.app.discussion tool'
|
|
|
|
id = 'portal_discussion'
|
|
|
|
|
|
|
|
def reindexObject(self, object):
|
|
|
|
"""Remove from catalog.
|
|
|
|
"""
|
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.reindexObject(object)
|
|
|
|
|
|
|
|
indexObject = reindexObject
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
def unindexObject(self, object):
|
|
|
|
"""Remove from catalog.
|
|
|
|
"""
|
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.unindexObject(object)
|
|
|
|
|
|
|
|
def uniqueValuesFor(self, name):
|
|
|
|
""" return unique values for FieldIndex name """
|
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.uniqueValuesFor(name)
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
def searchResults(self, REQUEST=None, **kw):
|
|
|
|
"""
|
|
|
|
Calls ZCatalog.searchResults with extra arguments that
|
|
|
|
limit the results to what the user is allowed to see.
|
|
|
|
"""
|
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
object_provides = [IComment.__identifier__]
|
2009-05-18 16:16:48 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
if 'object_provides' in kw:
|
|
|
|
kw_provides = kw['object_provides']
|
|
|
|
if isinstance(str, kw_provides):
|
|
|
|
object_provides.append(kw_provides)
|
|
|
|
else:
|
|
|
|
object_provides.extend(kw_provides)
|
2009-05-18 16:16:48 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
if REQUEST is not None and 'object_provides' in REQUEST.form:
|
|
|
|
rq_provides = REQUEST.form['object_provides']
|
|
|
|
del REQUEST.form['object_provides']
|
|
|
|
if isinstance(str, rq_provides):
|
|
|
|
object_provides.append(rq_provides)
|
|
|
|
else:
|
|
|
|
object_provides.extend(rq_provides)
|
2009-05-18 16:16:48 +02:00
|
|
|
|
2009-05-17 20:38:45 +02:00
|
|
|
kw['object_provides'] = object_provides
|
|
|
|
return catalog.searchResults(REQUEST, **kw)
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
def index_object(obj, event):
|
|
|
|
"""Index the object when added to the conversation
|
|
|
|
"""
|
2010-07-12 15:47:53 +02:00
|
|
|
tool = queryUtility(ICommentingTool)
|
2009-05-23 18:37:10 +02:00
|
|
|
if tool is not None:
|
|
|
|
tool.indexObject(obj)
|
2009-05-16 17:05:22 +02:00
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
def unindex_object(obj, event):
|
|
|
|
"""Unindex the object when removed
|
|
|
|
"""
|
2010-07-12 15:47:53 +02:00
|
|
|
tool = queryUtility(ICommentingTool)
|
2009-05-23 18:37:10 +02:00
|
|
|
if tool is not None:
|
|
|
|
tool.unindexObject(obj)
|