plone.app.discussion/plone/app/discussion/tool.py

76 lines
2.5 KiB
Python
Raw Permalink Normal View History

"""The portal_discussion tool, usually accessed via
queryUtility(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.
"""
2018-03-21 21:43:58 +01:00
from .interfaces import IComment
from .interfaces import ICommentingTool
from OFS.SimpleItem import SimpleItem
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import UniqueObject
from zope import interface
from zope.component import queryUtility
@interface.implementer(ICommentingTool)
class CommentingTool(UniqueObject, SimpleItem):
2022-05-01 23:14:09 +02:00
meta_type = "plone.app.discussion tool"
id = "portal_discussion"
def reindexObject(self, object):
# Reindex in catalog.
2022-05-01 23:14:09 +02:00
catalog = getToolByName(self, "portal_catalog")
return catalog.reindexObject(object)
indexObject = reindexObject
def unindexObject(self, object):
# Remove from catalog.
2022-05-01 23:14:09 +02:00
catalog = getToolByName(self, "portal_catalog")
return catalog.unindexObject(object)
def uniqueValuesFor(self, name):
# return unique values for FieldIndex name
2022-05-01 23:14:09 +02:00
catalog = getToolByName(self, "portal_catalog")
return catalog.uniqueValuesFor(name)
def searchResults(self, REQUEST=None, **kw):
# Calls ZCatalog.searchResults with extra arguments that
# limit the results to what the user is allowed to see.
2022-05-01 23:14:09 +02:00
catalog = getToolByName(self, "portal_catalog")
object_provides = [IComment.__identifier__]
2022-05-01 23:14:09 +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)
2022-05-01 23:14:09 +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)
2022-05-01 23:14:09 +02:00
kw["object_provides"] = object_provides
return catalog.searchResults(REQUEST, **kw)
2012-01-14 07:13:39 +01:00
def index_object(obj, event):
2022-05-01 23:14:09 +02:00
"""Index the object when added to the conversation"""
tool = queryUtility(ICommentingTool)
if tool is not None:
tool.indexObject(obj)
2012-01-14 07:13:39 +01:00
def unindex_object(obj, event):
2022-05-01 23:14:09 +02:00
"""Unindex the object when removed"""
tool = queryUtility(ICommentingTool)
if tool is not None:
tool.unindexObject(obj)