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
|
|
|
|
|
|
|
class Comment(Explicit, Traversable, RoleManager, Owned):
|
|
|
|
"""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-16 13:21:23 +02:00
|
|
|
def __init__(self, conversation=None, **kw):
|
2009-05-18 16:16:48 +02:00
|
|
|
self.comment_id = None # will be set by IConversation.addComment()
|
2009-05-16 13:21:23 +02:00
|
|
|
|
2009-05-13 16:54:06 +02:00
|
|
|
self.__parent__ = conversation
|
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-16 12:34:12 +02:00
|
|
|
for k, v in kw.items():
|
2009-05-11 18:52:16 +02:00
|
|
|
setattr(self, k, v)
|
2009-05-16 06:46:47 +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
|
|
|
|
|
|
|
|
CommentFactory = Factory(Comment)
|