2009-05-13 16:54:06 +02:00
|
|
|
"""The default comment class and factory.
|
2009-05-11 18:52:16 +02:00
|
|
|
"""
|
2009-05-16 12:34:12 +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
|
|
|
|
|
|
|
from Acquisition import Explicit
|
|
|
|
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
|
|
|
|
|
|
|
|
class Comment(DynamicType, Traversable, RoleManager, Owned, Explicit):
|
2009-05-11 18:52:16 +02:00
|
|
|
"""A comment.
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
implements(IComment)
|
|
|
|
|
|
|
|
meta_type = portal_type = 'Discussion Item'
|
|
|
|
|
|
|
|
__parent__ = None
|
2009-05-13 17:20:02 +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-05-13 16:54:06 +02:00
|
|
|
mime_type = "text/plain"
|
2009-05-11 18:52:16 +02:00
|
|
|
text = u""
|
|
|
|
|
|
|
|
creator = None
|
|
|
|
creation_date = None
|
|
|
|
modification_date = None
|
|
|
|
|
|
|
|
author_username = None
|
|
|
|
|
|
|
|
author_name = None
|
|
|
|
author_email = None
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# Note: we want to use zope.component.createObject() to instantiate
|
|
|
|
# comments as far as possible. comment_id and __parent__ are set via
|
|
|
|
# IConversation.addComment().
|
|
|
|
|
|
|
|
def __init__(self):
|
2009-05-16 12:34:12 +02:00
|
|
|
self.creation_date = self.modification_date = datetime.now()
|
2009-05-11 18:52:16 +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-05-13 17:20:02 +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-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
|
|
|
|
|
|
|
|
def Title(self):
|
|
|
|
"""The title of the comment
|
|
|
|
"""
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def Creator(self):
|
|
|
|
"""The name of the person who wrote the comment
|
|
|
|
"""
|
|
|
|
return self.creator
|
2009-05-23 18:12:45 +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-13 16:54:06 +02:00
|
|
|
|
|
|
|
CommentFactory = Factory(Comment)
|