2009-05-26 09:25:14 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
2009-05-25 20:59:25 +02:00
|
|
|
from zope.interface import implements
|
|
|
|
from zope.component import getMultiAdapter
|
|
|
|
from zope.viewlet.interfaces import IViewlet
|
2009-05-22 19:30:52 +02:00
|
|
|
|
2009-05-26 09:22:36 +02:00
|
|
|
from Acquisition import aq_inner, aq_parent
|
2009-05-25 20:59:25 +02:00
|
|
|
from Products.Five.browser import BrowserView
|
2009-05-22 19:30:52 +02:00
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
|
|
|
|
2009-05-26 21:58:33 +02:00
|
|
|
from plone.app.discussion.interfaces import IComment, IReplies
|
2009-05-25 20:59:25 +02:00
|
|
|
from plone.app.discussion.conversation import conversationAdapterFactory
|
2009-05-22 19:30:52 +02:00
|
|
|
|
2009-05-25 20:59:25 +02:00
|
|
|
from plone.app.discussion.comment import CommentFactory
|
|
|
|
|
|
|
|
from zope.component import createObject
|
|
|
|
|
2009-05-27 15:23:25 +02:00
|
|
|
class View(BrowserView):
|
|
|
|
"""Comment View
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
# Redirect from /path/to/object/++conversation++default/123456789
|
|
|
|
# to /path/to/object#comment-123456789
|
|
|
|
comment_id = aq_parent(self).id
|
|
|
|
self.request.response.redirect(aq_parent(aq_parent(aq_parent(self))).absolute_url() + '#comment-' + comment_id)
|
|
|
|
|
2009-05-25 20:59:25 +02:00
|
|
|
class CommentsViewlet(BrowserView):
|
|
|
|
"""Discussion Viewlet
|
|
|
|
"""
|
|
|
|
|
|
|
|
implements(IViewlet)
|
|
|
|
|
|
|
|
template = ViewPageTemplateFile('comments.pt')
|
|
|
|
|
|
|
|
def __init__(self, context, request, view, manager):
|
|
|
|
super(CommentsViewlet, self).__init__(context, request)
|
|
|
|
self.__parent__ = view
|
|
|
|
self.view = view
|
|
|
|
self.manager = manager
|
|
|
|
self.portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state")
|
2009-05-22 19:30:52 +02:00
|
|
|
|
|
|
|
def update(self):
|
2009-05-25 20:59:25 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def replies(self):
|
2009-05-27 08:58:00 +02:00
|
|
|
# Return all direct replies
|
2009-05-25 20:59:25 +02:00
|
|
|
conversation = conversationAdapterFactory(self.context)
|
2009-05-27 08:58:00 +02:00
|
|
|
return conversation.getThreads()
|
2009-05-25 20:59:25 +02:00
|
|
|
|
2009-05-26 09:25:14 +02:00
|
|
|
def format_time(self, time):
|
|
|
|
# TODO: to localized time not working!!!
|
|
|
|
#util = getToolByName(self.context, 'translation_service')
|
|
|
|
#return util.ulocalized_time(time, 1, self.context, domain='plonelocales')
|
|
|
|
return time
|
|
|
|
|
2009-05-25 20:59:25 +02:00
|
|
|
class AddComment(BrowserView):
|
|
|
|
"""Add a comment to a conversation
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
if self.request.has_key('form.button.AddComment'):
|
|
|
|
|
|
|
|
subject = self.request.get('subject')
|
|
|
|
text = self.request.get('body_text')
|
|
|
|
|
|
|
|
# The add-comment view is called on the conversation object
|
|
|
|
conversation = self.context
|
|
|
|
|
|
|
|
# Create the comment
|
|
|
|
comment = CommentFactory()
|
|
|
|
comment.title = subject
|
|
|
|
comment.text = text
|
|
|
|
|
|
|
|
# Add comment to the conversation
|
|
|
|
conversation.addComment(comment)
|
|
|
|
|
2009-05-26 21:58:33 +02:00
|
|
|
# Redirect to the document object page
|
|
|
|
self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url())
|
|
|
|
|
|
|
|
class ReplyToComment(BrowserView):
|
|
|
|
"""Reply to a comment
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
if self.request.has_key('form.button.AddComment'):
|
|
|
|
|
|
|
|
reply_to_comment_id = self.request.get('form.reply_to_comment_id')
|
|
|
|
subject = self.request.get('subject')
|
|
|
|
text = self.request.get('body_text')
|
|
|
|
|
|
|
|
# The add-comment view is called on the conversation object
|
|
|
|
conversation = self.context
|
|
|
|
|
|
|
|
# Fetch the comment we want to reply to
|
|
|
|
comment_to_reply_to = conversation.get(reply_to_comment_id)
|
|
|
|
|
|
|
|
replies = IReplies(comment_to_reply_to)
|
|
|
|
|
|
|
|
# Create the comment
|
|
|
|
comment = CommentFactory()
|
|
|
|
comment.title = subject
|
|
|
|
comment.text = text
|
|
|
|
|
|
|
|
# Add the reply to the comment
|
|
|
|
new_re_id = replies.addComment(comment)
|
|
|
|
|
2009-05-26 22:02:42 +02:00
|
|
|
# Redirect to the document object page
|
2009-05-26 09:22:36 +02:00
|
|
|
self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url())
|