2009-05-13 16:54:06 +02:00
|
|
|
"""The default comment class and factory.
|
2009-05-11 18:52:16 +02:00
|
|
|
"""
|
2009-05-30 08:08:44 +02:00
|
|
|
from datetime import datetime
|
2009-05-13 16:54:06 +02:00
|
|
|
from zope.interface import implements
|
|
|
|
from zope.component.factory import Factory
|
2009-05-11 18:52:16 +02:00
|
|
|
|
2009-07-04 18:18:48 +02:00
|
|
|
from Acquisition import aq_parent, Implicit
|
2009-05-11 18:52:16 +02:00
|
|
|
from AccessControl.Role import RoleManager
|
|
|
|
from AccessControl.Owned import Owned
|
|
|
|
|
2009-10-17 18:29:45 +02:00
|
|
|
from Globals import Persistent
|
2009-05-11 18:52:16 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
from Products.CMFCore.DynamicType import DynamicType
|
2009-10-17 18:29:45 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
|
|
|
from OFS.Traversable import Traversable
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IComment
|
2009-10-16 14:11:58 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
# Plone 4:
|
|
|
|
# Mixin CatalogAware and WorkflowAware into the Comment class
|
|
|
|
# is necessary for comments to be indexed in Plone4.
|
|
|
|
from Products.CMFCore.CMFCatalogAware import CatalogAware
|
|
|
|
from Products.CMFCore.CMFCatalogAware import WorkflowAware
|
|
|
|
except:
|
|
|
|
# Plone 3:
|
|
|
|
# Dummy imports to make Comment class happy
|
|
|
|
from OFS.Traversable import Traversable as CatalogAware
|
|
|
|
from OFS.Traversable import Traversable as WorkflowAware
|
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
|
2009-10-17 18:29:45 +02:00
|
|
|
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
|
|
|
|
RoleManager, Owned, Implicit, Persistent):
|
2009-05-11 18:52:16 +02:00
|
|
|
"""A comment.
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
This object attempts to be as lightweight as possible. We implement a
|
|
|
|
number of standard methods instead of subclassing, to have total control
|
|
|
|
over what goes into the object.
|
|
|
|
"""
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
implements(IComment)
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-06-24 10:25:11 +02:00
|
|
|
meta_type = portal_type = 'Discussion Item'
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
__parent__ = None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-18 16:16:48 +02:00
|
|
|
comment_id = None # long
|
|
|
|
in_reply_to = None # long
|
2009-05-11 18:52:16 +02:00
|
|
|
|
|
|
|
title = u""
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-13 16:54:06 +02:00
|
|
|
mime_type = "text/plain"
|
2009-05-11 18:52:16 +02:00
|
|
|
text = u""
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
creator = None
|
|
|
|
creation_date = None
|
|
|
|
modification_date = None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
author_username = None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
author_name = None
|
|
|
|
author_email = None
|
2010-02-08 13:02:54 +01:00
|
|
|
|
|
|
|
author_notification = None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
|
|
|
# Note: we want to use zope.component.createObject() to instantiate
|
2009-05-18 17:15:36 +02:00
|
|
|
# comments as far as possible. comment_id and __parent__ are set via
|
|
|
|
# IConversation.addComment().
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def __init__(self):
|
2009-05-30 08:08:44 +02:00
|
|
|
self.creation_date = self.modification_date = datetime.now()
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-13 17:20:02 +02:00
|
|
|
@property
|
|
|
|
def __name__(self):
|
2009-05-18 16:16:48 +02:00
|
|
|
return self.comment_id and unicode(self.comment_id) or None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
@property
|
|
|
|
def id(self):
|
2009-05-18 16:16:48 +02:00
|
|
|
return self.comment_id and str(self.comment_id) or None
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-11 18:52:16 +02:00
|
|
|
def getId(self):
|
2009-05-13 16:54:06 +02:00
|
|
|
"""The id of the comment, as a string
|
|
|
|
"""
|
|
|
|
return self.id
|
2009-10-16 14:11:58 +02:00
|
|
|
|
2009-08-20 04:06:15 +02:00
|
|
|
def getText(self):
|
|
|
|
'''the text'''
|
|
|
|
return self.text
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-13 16:54:06 +02:00
|
|
|
def Title(self):
|
|
|
|
"""The title of the comment
|
|
|
|
"""
|
|
|
|
return self.title
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-13 16:54:06 +02:00
|
|
|
def Creator(self):
|
|
|
|
"""The name of the person who wrote the comment
|
|
|
|
"""
|
|
|
|
return self.creator
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-06-24 10:25:11 +02:00
|
|
|
def Type(self):
|
|
|
|
"""The Discussion Item content type
|
|
|
|
"""
|
2009-06-24 15:18:54 +02:00
|
|
|
return self.portal_type
|
2009-06-24 10:25:11 +02:00
|
|
|
|
2009-10-16 14:11:58 +02:00
|
|
|
# CMF's event handlers assume any IDynamicType has these :(
|
|
|
|
|
|
|
|
def opaqueItems(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def opaqueIds(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def opaqueValues(self):
|
|
|
|
return []
|
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
CommentFactory = Factory(Comment)
|
|
|
|
|
|
|
|
def notify_workflow(obj, event):
|
|
|
|
"""Tell the workflow tool when a comment is added
|
|
|
|
"""
|
|
|
|
tool = getToolByName(obj, 'portal_workflow', None)
|
|
|
|
if tool is not None:
|
2009-07-04 18:18:48 +02:00
|
|
|
tool.notifyCreated(obj)
|
|
|
|
|
|
|
|
def notify_content_object(obj, event):
|
|
|
|
"""Tell the content object when a comment is added
|
|
|
|
"""
|
|
|
|
content_obj = aq_parent(aq_parent(obj))
|
2009-08-20 04:06:15 +02:00
|
|
|
content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators',))
|
2010-02-08 13:02:54 +01:00
|
|
|
|
|
|
|
def notify_user(obj, event):
|
|
|
|
"""Tell the user when a comment is added
|
|
|
|
"""
|
|
|
|
acl_users = getToolByName(obj, 'acl_users')
|
|
|
|
mail_host = getToolByName(obj, 'MailHost')
|
|
|
|
portal_url = getToolByName(obj, 'portal_url')
|
|
|
|
|
|
|
|
portal = portal_url.getPortalObject()
|
|
|
|
sender = portal.getProperty('email_from_address')
|
|
|
|
|
|
|
|
if not sender:
|
|
|
|
return
|
|
|
|
|
|
|
|
subject = "Is this you?"
|
|
|
|
message = "A presenter called %s was added here %s" % (obj.title, obj.absolute_url(),)
|
|
|
|
|
|
|
|
matching_users = acl_users.searchUsers(fullname=obj.title)
|
|
|
|
for user_info in matching_users:
|
|
|
|
email = user_info.get('email', None)
|
|
|
|
if email is not None:
|
|
|
|
mail_host.secureSend(message, email, sender, subject)
|