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-06-13 18:46:37 +02:00
|
|
|
from Acquisition import Implicit
|
2009-05-11 18:52:16 +02:00
|
|
|
from OFS.Traversable import Traversable
|
|
|
|
from AccessControl.Role import RoleManager
|
|
|
|
from AccessControl.Owned import Owned
|
|
|
|
|
2009-05-13 16:54:06 +02:00
|
|
|
from plone.app.discussion.interfaces import IComment
|
2009-05-11 18:52:16 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
from Products.CMFCore.DynamicType import DynamicType
|
2009-05-23 18:37:10 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2009-05-23 18:12:45 +02:00
|
|
|
|
2009-06-13 18:46:37 +02:00
|
|
|
class Comment(DynamicType, Traversable, RoleManager, Owned, Implicit):
|
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
|
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-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-05-23 18:12:45 +02:00
|
|
|
# CMF's event handlers assume any IDynamicType has these :(
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
def opaqueItems(self):
|
|
|
|
return []
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
def opaqueIds(self):
|
|
|
|
return []
|
2009-06-13 18:46:37 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
def opaqueValues(self):
|
|
|
|
return []
|
2009-05-13 16:54:06 +02:00
|
|
|
|
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:
|
|
|
|
tool.notifyCreated(obj)
|