This commit is contained in:
Timo Stollenwerk 2013-04-18 16:12:00 +02:00
parent 607719fd42
commit 73d84a22d7
2 changed files with 78 additions and 50 deletions

View File

@ -52,20 +52,20 @@ COMMENT_TITLE = _(
MAIL_NOTIFICATION_MESSAGE = _( MAIL_NOTIFICATION_MESSAGE = _(
u"mail_notification_message", u"mail_notification_message",
default=u"A comment on '${title}' " default=u"A comment on '${title}' "
"has been posted here: ${link}\n\n" u"has been posted here: ${link}\n\n"
"---\n" u"---\n"
"${text}\n" u"${text}\n"
"---\n") u"---\n")
MAIL_NOTIFICATION_MESSAGE_MODERATOR = _( MAIL_NOTIFICATION_MESSAGE_MODERATOR = _(
u"mail_notification_message_moderator", u"mail_notification_message_moderator",
default=u"A comment on '${title}' " default=u"A comment on '${title}' "
"has been posted here: ${link}\n\n" u"has been posted here: ${link}\n\n"
"---\n" u"---\n"
"${text}\n" u"${text}\n"
"---\n\n" u"---\n\n"
"Approve comment:\n${link_approve}\n\n" u"Approve comment:\n${link_approve}\n\n"
"Delete comment:\n${link_delete}\n") u"Delete comment:\n${link_delete}\n")
logger = logging.getLogger("plone.app.discussion") logger = logging.getLogger("plone.app.discussion")
@ -154,12 +154,13 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
return transform.getData() return transform.getData()
else: else:
logger = logging.getLogger("plone.app.discussion") logger = logging.getLogger("plone.app.discussion")
logger.error( logger.error(_(
_(u"Transform '%s' => '%s' not available. Failed to transform comment '%s'." % ( u"Transform '%s' => '%s' not available." % (
sourceMimetype, sourceMimetype,
targetMimetype, targetMimetype
self.absolute_url(), ) +
))) u"Failed to transform comment '%s'." % self.absolute_url()
))
return text return text
def Title(self): def Title(self):
@ -170,8 +171,12 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
return self.title return self.title
if not self.author_name: if not self.author_name:
author_name = translate(Message(_(u"label_anonymous", author_name = translate(
default=u"Anonymous"))) Message(_(
u"label_anonymous",
default=u"Anonymous"
))
)
else: else:
author_name = self.author_name author_name = self.author_name
@ -190,6 +195,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
return self.creator return self.creator
security.declareProtected(permissions.View, 'Type') security.declareProtected(permissions.View, 'Type')
def Type(self): def Type(self):
"""The Discussion Item content type. """The Discussion Item content type.
""" """
@ -240,23 +246,30 @@ def notify_content_object_moved(obj, event):
"""Update all comments of a content object that has been moved. """Update all comments of a content object that has been moved.
""" """
if event.oldParent is None or event.newParent is None \ if event.oldParent is None or event.newParent is None \
or event.oldName is None or event.newName is None: or event.oldName is None or event.newName is None:
return return
# This method is also called for sublocations of moved objects. We therefore can't # This method is also called for sublocations of moved objects. We
# assume that event.object == obj and event.{old,new}{Parent,Name} may refer to # therefore can't assume that event.object == obj and event.
# the actually moved object further up in the object hierarchy. # {old,new}{Parent,Name} may refer to the actually moved object further up
# The object is already moved at this point. so obj.getPhysicalPath retruns the new path. # in the object hierarchy. The object is already moved at this point. so
# get the part of the path that was moved. # obj.getPhysicalPath retruns the new path get the part of the path that
moved_path = obj.getPhysicalPath()[len(event.newParent.getPhysicalPath()) + 1:] # was moved.
moved_path = obj.getPhysicalPath()[
len(event.newParent.getPhysicalPath()) + 1:
]
# Remove comments at the old location from catalog # Remove comments at the old location from catalog
catalog = getToolByName(obj, 'portal_catalog') catalog = getToolByName(obj, 'portal_catalog')
old_path = '/'.join(event.oldParent.getPhysicalPath() + (event.oldName,) + moved_path) old_path = '/'.join(
event.oldParent.getPhysicalPath() +
(event.oldName,) +
moved_path
)
brains = catalog.searchResults(dict( brains = catalog.searchResults(dict(
path={'query': old_path}, path={'query': old_path},
portal_type="Discussion Item" portal_type="Discussion Item"
)) ))
for brain in brains: for brain in brains:
catalog.uncatalog_object(brain.getPath()) catalog.uncatalog_object(brain.getPath())
# Reindex comment at the new location # Reindex comment at the new location
@ -301,8 +314,9 @@ def notify_user(obj, event):
# when he has commented multiple times. # when he has commented multiple times.
emails = set() emails = set()
for comment in conversation.getComments(): for comment in conversation.getComments():
if (obj != comment and obj_is_not_the_comment = obj != comment
comment.user_notification and comment.author_email): valid_user_email = comment.user_notification and comment.author_email
if obj_is_not_the_comment and valid_user_email:
emails.add(comment.author_email) emails.add(comment.author_email)
if not emails: if not emails:
@ -310,13 +324,17 @@ def notify_user(obj, event):
subject = translate(_(u"A comment has been posted."), subject = translate(_(u"A comment has been posted."),
context=obj.REQUEST) context=obj.REQUEST)
message = translate(Message( message = translate(
Message(
MAIL_NOTIFICATION_MESSAGE, MAIL_NOTIFICATION_MESSAGE,
mapping={'title': safe_unicode(content_object.title), mapping={
'link': content_object.absolute_url() + 'title': safe_unicode(content_object.title),
'/view#' + obj.id, 'link': content_object.absolute_url() + '/view#' + obj.id,
'text': obj.text}), 'text': obj.text
context=obj.REQUEST) }
),
context=obj.REQUEST
)
for email in emails: for email in emails:
# Send email # Send email
try: try:
@ -371,15 +389,21 @@ def notify_moderator(obj, event):
# Compose email # Compose email
subject = translate(_(u"A comment has been posted."), context=obj.REQUEST) subject = translate(_(u"A comment has been posted."), context=obj.REQUEST)
message = translate(Message(MAIL_NOTIFICATION_MESSAGE_MODERATOR, link_approve = obj.absolute_url() + '/@@moderate-publish-comment'
mapping={ link_delete = obj.absolute_url() + '/@@moderate-delete-comment'
'title': safe_unicode(content_object.title), message = translate(
'link': content_object.absolute_url() + '/view#' + obj.id, Message(
'text': obj.text, MAIL_NOTIFICATION_MESSAGE_MODERATOR,
'link_approve': obj.absolute_url() + '/@@moderate-publish-comment', mapping={
'link_delete': obj.absolute_url() + '/@@moderate-delete-comment', 'title': safe_unicode(content_object.title),
}), 'link': content_object.absolute_url() + '/view#' + obj.id,
context=obj.REQUEST) 'text': obj.text,
'link_approve': link_approve,
'link_delete': link_delete,
}
),
context=obj.REQUEST
)
# Send email # Send email
try: try:

View File

@ -89,8 +89,10 @@ class Conversation(Traversable, Persistent, Explicit):
@property @property
def total_comments(self): def total_comments(self):
public_comments = [x for x in self._comments.values() if \ public_comments = [
user_nobody.has_permission('View', x)] x for x in self._comments.values()
if user_nobody.has_permission('View', x)
]
return len(public_comments) return len(public_comments)
@property @property
@ -428,9 +430,11 @@ class CommentReplies(ConversationReplies):
def __init__(self, context): def __init__(self, context):
self.comment = context self.comment = context
self.conversation = aq_parent(self.comment) self.conversation = aq_parent(self.comment)
conversation_has_no_children = not hasattr(
if (self.conversation is None or self.conversation,
not hasattr(self.conversation, '_children')): '_children'
)
if self.conversation is None or conversation_has_no_children:
raise TypeError("This adapter doesn't know what to do with the " raise TypeError("This adapter doesn't know what to do with the "
"parent conversation") "parent conversation")