2009-06-10 22:14:44 +02:00
|
|
|
from Acquisition import aq_inner, aq_parent
|
|
|
|
|
|
|
|
from Products.Five.browser import BrowserView
|
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
|
|
|
|
2009-06-28 13:49:00 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2009-07-07 10:00:41 +02:00
|
|
|
from Products.CMFPlone import PloneMessageFactory as _
|
|
|
|
|
|
|
|
from Products.statusmessages.interfaces import IStatusMessage
|
|
|
|
|
2009-06-10 22:14:44 +02:00
|
|
|
class View(BrowserView):
|
2009-06-29 15:38:00 +02:00
|
|
|
"""Moderation View
|
2009-06-10 22:14:44 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
template = ViewPageTemplateFile('moderation.pt')
|
2009-08-20 04:11:57 +02:00
|
|
|
try:
|
|
|
|
template.id = '@@moderate-comments'
|
|
|
|
except AttributeError:
|
|
|
|
# id is not writeable in Zope 2.12
|
|
|
|
pass
|
2009-06-10 22:14:44 +02:00
|
|
|
|
|
|
|
def __call__(self):
|
2009-10-07 13:52:44 +02:00
|
|
|
# Hide the editable-object border
|
|
|
|
self.request.set('disable_border', True)
|
2009-06-26 16:57:45 +02:00
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
|
2009-06-29 13:11:58 +02:00
|
|
|
if self.request.has_key('form.button.Filter'):
|
|
|
|
self.filter = self.request.get('form.button.Filter')
|
|
|
|
if self.filter == 'pending':
|
|
|
|
self.comments = self.comments_pending()
|
|
|
|
elif self.filter == "published":
|
|
|
|
self.comments = self.comments_published()
|
|
|
|
else:
|
|
|
|
raise ValueError('Value %s for filter is not know.' % self.filter)
|
2009-06-26 16:57:45 +02:00
|
|
|
else:
|
|
|
|
self.comments = self.comments_all()
|
2009-06-10 22:14:44 +02:00
|
|
|
return self.template()
|
|
|
|
|
2009-06-28 20:38:25 +02:00
|
|
|
def cook(self, text):
|
|
|
|
return text
|
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
def moderation_enabled(self):
|
|
|
|
"""Returns true if comment moderation workflow is
|
|
|
|
enabled on 'Discussion Item' content type.
|
|
|
|
"""
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
wf_tool = getToolByName(context, 'portal_workflow')
|
|
|
|
if wf_tool.getChainForPortalType('Discussion Item') \
|
|
|
|
== ('comment_review_workflow',):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2009-06-10 22:14:44 +02:00
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
def comments_all(self, start=0, size=None):
|
|
|
|
"""Returns all comments.
|
|
|
|
"""
|
2009-06-10 22:14:44 +02:00
|
|
|
self.state = self.request.get('review_state', 'pending')
|
2009-06-29 11:54:17 +02:00
|
|
|
self.transition = self.request.get('publish_transition', 'publish')
|
2009-06-10 22:14:44 +02:00
|
|
|
self.limit = self.request.get('limit', 100)
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
|
|
|
|
return catalog(
|
2009-06-26 16:57:45 +02:00
|
|
|
portal_type='Discussion Item',
|
|
|
|
sort_on='created',
|
2009-07-03 08:45:29 +02:00
|
|
|
sort_order='reverse',
|
2009-06-26 16:57:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def comments_pending(self, start=0, size=None):
|
2009-10-18 15:12:52 +02:00
|
|
|
"""Returns all comments with 'pending' review state.
|
|
|
|
"""
|
2009-06-26 16:57:45 +02:00
|
|
|
self.state = self.request.get('review_state', 'pending')
|
|
|
|
self.transition = self.request.get('publish_transition', 'publish')
|
|
|
|
self.limit = self.request.get('limit', 100)
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
|
|
|
|
return catalog(
|
2009-06-10 22:14:44 +02:00
|
|
|
portal_type='Discussion Item',
|
|
|
|
review_state=self.state,
|
|
|
|
sort_on='created',
|
2009-07-03 08:45:29 +02:00
|
|
|
sort_order='reverse',
|
2009-06-26 16:57:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def comments_published(self, start=0, size=None):
|
2009-10-18 15:12:52 +02:00
|
|
|
"""Returns all comments with 'published' review state.
|
|
|
|
"""
|
2009-06-26 16:57:45 +02:00
|
|
|
self.state = self.request.get('review_state', 'pending')
|
|
|
|
self.transition = self.request.get('publish_transition', 'pending')
|
|
|
|
self.limit = self.request.get('limit', 100)
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
|
|
|
|
|
|
|
return catalog(
|
|
|
|
portal_type='Discussion Item',
|
|
|
|
review_state='published',
|
|
|
|
sort_on='created',
|
2009-07-03 08:45:29 +02:00
|
|
|
sort_order='reverse',
|
2009-06-26 16:57:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def comments_spam(self, start=0, size=None):
|
2009-10-18 15:12:52 +02:00
|
|
|
"""Returns all comments that are marked as spam.
|
|
|
|
|
|
|
|
Not implemented yet.
|
|
|
|
"""
|
2009-06-26 16:57:45 +02:00
|
|
|
return None
|
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class DeleteComment(BrowserView):
|
|
|
|
"""Delete a comment from a conversation
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
comment_id = self.context.id
|
|
|
|
|
|
|
|
conversation = aq_parent(context)
|
|
|
|
|
|
|
|
del conversation[comment_id]
|
|
|
|
|
2009-07-07 10:00:41 +02:00
|
|
|
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
|
|
|
_("Comment deleted."),
|
|
|
|
type="info")
|
|
|
|
|
|
|
|
return self.context.REQUEST.RESPONSE.redirect(self.context.REQUEST.HTTP_REFERER)
|
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class PublishComment(BrowserView):
|
|
|
|
"""Publish a comment
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
comment = aq_inner(self.context)
|
|
|
|
comment_id = self.context.id
|
|
|
|
|
2009-10-17 18:14:44 +02:00
|
|
|
workflow_action = self.request.form['workflow_action']
|
2009-06-26 16:57:45 +02:00
|
|
|
portal_workflow = getToolByName(comment, 'portal_workflow')
|
|
|
|
portal_workflow.doActionFor(comment, workflow_action)
|
|
|
|
|
|
|
|
catalog = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalog.reindexObject(comment)
|
|
|
|
|
2009-07-07 10:00:41 +02:00
|
|
|
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
|
|
|
_("Comment published."),
|
|
|
|
type="info")
|
|
|
|
|
|
|
|
return self.context.REQUEST.RESPONSE.redirect(self.context.REQUEST.HTTP_REFERER)
|
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class BulkActionsView(BrowserView):
|
|
|
|
"""Bulk actions (unapprove, approve, delete, mark as spam).
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
|
2009-06-29 15:38:00 +02:00
|
|
|
if self.request.has_key('form.select.BulkAction'):
|
2009-06-26 16:57:45 +02:00
|
|
|
|
2009-06-26 20:59:37 +02:00
|
|
|
bulkaction = self.request.get('form.select.BulkAction')
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
self.paths = self.request.get('paths')
|
2009-06-29 17:09:41 +02:00
|
|
|
if self.paths:
|
|
|
|
if bulkaction == '-1':
|
|
|
|
# no bulk action was selected
|
|
|
|
pass
|
|
|
|
elif bulkaction == 'retract':
|
|
|
|
self.retract()
|
|
|
|
elif bulkaction == 'publish':
|
|
|
|
self.publish()
|
|
|
|
elif bulkaction == 'mark_as_spam':
|
|
|
|
self.mark_as_spam()
|
|
|
|
elif bulkaction == 'delete':
|
|
|
|
self.delete()
|
|
|
|
else:
|
|
|
|
raise KeyError
|
2009-06-26 20:59:37 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def retract(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def publish(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
context = aq_inner(self.context)
|
2009-06-29 15:44:46 +02:00
|
|
|
for path in self.paths:
|
2009-06-26 20:59:37 +02:00
|
|
|
comment = context.restrictedTraverse(path)
|
|
|
|
portal_workflow = getToolByName(comment, 'portal_workflow')
|
2009-06-29 15:52:51 +02:00
|
|
|
current_state = portal_workflow.getInfoFor(comment, 'review_state')
|
|
|
|
if current_state != 'published':
|
|
|
|
portal_workflow.doActionFor(comment, 'publish')
|
2009-06-26 20:59:37 +02:00
|
|
|
catalog = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalog.reindexObject(comment)
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def mark_as_spam(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def delete(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
context = aq_inner(self.context)
|
2009-06-29 15:44:46 +02:00
|
|
|
for path in self.paths:
|
2009-06-26 20:59:37 +02:00
|
|
|
comment = context.restrictedTraverse(path)
|
|
|
|
conversation = aq_parent(comment)
|
|
|
|
del conversation[comment.id]
|