plone.app.discussion/plone/app/discussion/comment.py
Carsten Senger e946ef7979 Add an accessor method for title. As title is part of the interface
IComment for which we <require> zope2.View a permission check will raise
Unauthorized cause we can not assure that the user's userfolder is in 
the acqusition chain of the object (the attribute is a bare unicode object).
It works for methods. im_self is used to get the acquisition wrapped
object.

svn path=/plone.app.discussion/trunk/; revision=29199
2009-08-20 02:06:15 +00:00

112 lines
2.7 KiB
Python

"""The default comment class and factory.
"""
from datetime import datetime
from zope.interface import implements
from zope.component.factory import Factory
from Acquisition import aq_parent, Implicit
from OFS.Traversable import Traversable
from AccessControl.Role import RoleManager
from AccessControl.Owned import Owned
from plone.app.discussion.interfaces import IComment
from Products.CMFCore.DynamicType import DynamicType
from Products.CMFCore.utils import getToolByName
class Comment(DynamicType, Traversable, RoleManager, Owned, Implicit):
"""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
comment_id = None # long
in_reply_to = None # long
title = u""
mime_type = "text/plain"
text = u""
creator = None
creation_date = None
modification_date = None
author_username = None
author_name = None
author_email = None
# 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):
self.creation_date = self.modification_date = datetime.now()
@property
def __name__(self):
return self.comment_id and unicode(self.comment_id) or None
@property
def id(self):
return self.comment_id and str(self.comment_id) or None
def getId(self):
"""The id of the comment, as a string
"""
return self.id
def getText(self):
'''the text'''
return self.text
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
def Type(self):
"""The Discussion Item content type
"""
return self.portal_type
# CMF's event handlers assume any IDynamicType has these :(
def opaqueItems(self):
return []
def opaqueIds(self):
return []
def opaqueValues(self):
return []
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)
def notify_content_object(obj, event):
"""Tell the content object when a comment is added
"""
content_obj = aq_parent(aq_parent(obj))
content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators',))