From 73d84a22d796342999cffb308689e2bdf8d2e636 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 18 Apr 2013 16:12:00 +0200 Subject: [PATCH] Pep8. --- plone/app/discussion/comment.py | 114 ++++++++++++++++----------- plone/app/discussion/conversation.py | 14 ++-- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 93bab67..9d9b1e1 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -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. """ @@ -240,23 +246,30 @@ def notify_content_object_moved(obj, event): """Update all comments of a content object that has been moved. """ 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 - # 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" - )) + path={'query': old_path}, + portal_type="Discussion Item" + )) for brain in brains: catalog.uncatalog_object(brain.getPath()) # Reindex comment at the new location @@ -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, - 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 = 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': link_approve, + 'link_delete': link_delete, + } + ), + context=obj.REQUEST + ) # Send email try: diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index 6e529a8..4ec6c75 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -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")