Make sure comment titles work with special characters as well.

svn path=/plone.app.discussion/trunk/; revision=40486
This commit is contained in:
Timo Stollenwerk 2010-10-02 18:16:49 +00:00
parent 51d6c60412
commit e0055d0ba7
2 changed files with 18 additions and 7 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""The default comment class and factory.
"""
from datetime import datetime
@ -47,7 +48,7 @@ except:
PLONE_4 = False
COMMENT_TITLE = _(u"comment_title",
default=u"${creator} on ${content}")
default=u"${creator} on ${content}")
MAIL_NOTIFICATION_MESSAGE = _(u"mail_notification_message",
default=u"A comment with the title '${title}' "
@ -118,21 +119,20 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
def Title(self):
"""The title of the comment.
"""
if not self.creator:
creator = _(u"label_anonymous",
default=u"Anonymous")
creator = translate(Message(_(u"label_anonymous",
default=u"Anonymous")))
else:
creator = self.creator
creator = creator.decode("utf-8")
# Fetch the content object (the parent of the comment is the
# conversation, the parent of the conversation is the content object).
content = aq_base(self.__parent__.__parent__)
title = translate(
Message(COMMENT_TITLE,
mapping={'creator': creator,
'content': content.Title()}))
'content': content.Title().decode("utf-8")}))
return title
def Creator(self):

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import datetime
import logging
@ -72,6 +73,16 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment1)
self.assertEquals("Anonymous on Document 1", comment1.Title())
def test_title_special_characters(self):
self.portal.invokeFactory(id='doc_sp_chars',
title='Document äüö',
type_name='Document')
conversation = IConversation(self.portal.doc_sp_chars)
comment1 = createObject('plone.Comment')
comment1.creator = "Tarek Ziadé"
conversation.addComment(comment1)
self.assertEquals(u"Tarek Ziadé on Document äüö", comment1.Title())
def test_creator(self):
comment1 = createObject('plone.Comment')
comment1.creator = "Jim"