2016-02-05 01:39:53 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-05-18 14:16:48 +00:00
|
|
|
"""The portal_discussion tool, usually accessed via
|
2010-07-12 13:49:57 +00:00
|
|
|
queryUtility(ICommentingTool). The default implementation delegates to the
|
2009-05-18 14:16:48 +00:00
|
|
|
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
|
2016-02-05 01:39:53 +01:00
|
|
|
from OFS.SimpleItem import SimpleItem
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
from Products.CMFCore.utils import UniqueObject
|
2009-05-16 15:05:22 +00:00
|
|
|
from zope import interface
|
2010-07-12 13:47:53 +00:00
|
|
|
from zope.component import queryUtility
|
2009-05-16 15:05:22 +00:00
|
|
|
|
2010-09-20 10:03:38 +00:00
|
|
|
|
2016-07-05 23:12:08 +02:00
|
|
|
@interface.implementer(ICommentingTool)
|
2009-05-17 18:38:45 +00:00
|
|
|
class CommentingTool(UniqueObject, SimpleItem):
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
meta_type = 'plone.app.discussion tool'
|
|
|
|
id = 'portal_discussion'
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
def reindexObject(self, object):
|
2016-05-04 10:40:36 +02:00
|
|
|
# Reindex in catalog.
|
2009-05-17 18:38:45 +00:00
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.reindexObject(object)
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
indexObject = reindexObject
|
2009-05-16 15:05:22 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
def unindexObject(self, object):
|
2016-05-04 10:40:36 +02:00
|
|
|
# Remove from catalog.
|
2009-05-17 18:38:45 +00:00
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.unindexObject(object)
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
def uniqueValuesFor(self, name):
|
2016-05-04 10:40:36 +02:00
|
|
|
# return unique values for FieldIndex name
|
2009-05-17 18:38:45 +00:00
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
return catalog.uniqueValuesFor(name)
|
2009-05-16 15:05:22 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
def searchResults(self, REQUEST=None, **kw):
|
2016-05-04 10:40:36 +02:00
|
|
|
# Calls ZCatalog.searchResults with extra arguments that
|
|
|
|
# limit the results to what the user is allowed to see.
|
2009-05-17 18:38:45 +00:00
|
|
|
catalog = getToolByName(self, 'portal_catalog')
|
|
|
|
object_provides = [IComment.__identifier__]
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00: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)
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00: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)
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2009-05-17 18:38:45 +00:00
|
|
|
kw['object_provides'] = object_provides
|
|
|
|
return catalog.searchResults(REQUEST, **kw)
|
2009-05-16 15:05:22 +00:00
|
|
|
|
2012-01-14 07:13:39 +01:00
|
|
|
|
2009-05-23 16:37:10 +00:00
|
|
|
def index_object(obj, event):
|
|
|
|
"""Index the object when added to the conversation
|
|
|
|
"""
|
2010-07-12 13:47:53 +00:00
|
|
|
tool = queryUtility(ICommentingTool)
|
2009-05-23 16:37:10 +00:00
|
|
|
if tool is not None:
|
|
|
|
tool.indexObject(obj)
|
2010-12-15 23:52:56 +00:00
|
|
|
|
2012-01-14 07:13:39 +01:00
|
|
|
|
2009-05-23 16:37:10 +00:00
|
|
|
def unindex_object(obj, event):
|
|
|
|
"""Unindex the object when removed
|
|
|
|
"""
|
2010-07-12 13:47:53 +00:00
|
|
|
tool = queryUtility(ICommentingTool)
|
2009-05-23 16:37:10 +00:00
|
|
|
if tool is not None:
|
|
|
|
tool.unindexObject(obj)
|