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

View File

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