From 22db0b1c784e7932b3a0c1df3c6fa9b3b6a4f9d5 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Wed, 29 Sep 2010 10:52:11 +0000 Subject: [PATCH] Fix comment title for anonymous commentators that do not provide a name. svn path=/plone.app.discussion/trunk/; revision=40435 --- plone/app/discussion/comment.py | 8 +++++--- plone/app/discussion/tests/test_catalog.py | 14 ++++++++++++++ plone/app/discussion/tests/test_comment.py | 8 +++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 5cacdc2..d21438b 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -120,8 +120,10 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, """ if not self.creator: - anonymous = _(u"label_anonymous", - default=u"Anonymous") + creator = _(u"label_anonymous", + default=u"Anonymous") + else: + creator = self.creator # Fetch the content object (the parent of the comment is the # conversation, the parent of the conversation is the content object). @@ -129,7 +131,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, title = translate( Message(COMMENT_TITLE, - mapping={'creator': self.creator, + mapping={'creator': creator, 'content': content.Title()})) return title diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py index 23c199e..da7924f 100644 --- a/plone/app/discussion/tests/test_catalog.py +++ b/plone/app/discussion/tests/test_catalog.py @@ -232,6 +232,20 @@ class CommentCatalogTest(PloneTestCase): def test_title(self): self.assertEquals(self.comment_brain.Title, 'Jim on Document 1') + + def test_no_name_title(self): + comment = createObject('plone.Comment') + comment.text = 'Comment text' + cid = self.conversation.addComment(comment) + + # Comment brain + comment = self.portal.doc1.restrictedTraverse( + '++conversation++default/%s' % cid) + brains = self.catalog.searchResults( + path = {'query' : + '/'.join(comment.getPhysicalPath()) }) + comment_brain = brains[0] + self.assertEquals(comment_brain.Title, "Anonymous on Document 1") def test_type(self): self.assertEquals(self.comment_brain.portal_type, 'Discussion Item') diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index bc1a49d..2cb38a0 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -65,7 +65,13 @@ class CommentTest(PloneTestCase): comment1.creator = "Jim Fulton" conversation.addComment(comment1) self.assertEquals("Jim Fulton on Document 1", comment1.Title()) - + + def test_no_name_title(self): + conversation = IConversation(self.portal.doc1) + comment1 = createObject('plone.Comment') + conversation.addComment(comment1) + self.assertEquals("Anonymous on Document 1", comment1.Title()) + def test_creator(self): comment1 = createObject('plone.Comment') comment1.creator = "Jim"