From 0c947077437d29c2485087e786fee9be48e5d1d6 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Mon, 29 Nov 2010 22:42:20 +0000 Subject: [PATCH] Dynamically show the comment formatting message dependent on the text transform setting. svn path=/plone.app.discussion/trunk/; revision=46035 --- CHANGES.txt | 4 +++ plone/app/discussion/browser/comments.pt | 2 +- plone/app/discussion/browser/comments.py | 28 +++++++++++++++++++ .../discussion/tests/test_comments_viewlet.py | 21 ++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index a8eb457..9d9483e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Changelog 1.0RC1 (unreleased) ------------------- +- Dynamically show the comment formatting message dependent on the text + transform setting. + [timo] + - Description for text transform added to the discussion control panel. [timo] diff --git a/plone/app/discussion/browser/comments.pt b/plone/app/discussion/browser/comments.pt index 5495099..76ff213 100644 --- a/plone/app/discussion/browser/comments.pt +++ b/plone/app/discussion/browser/comments.pt @@ -145,7 +145,7 @@
Add comment -

+

You can add a comment by filling out the form below. Plain text formatting.

diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index c6bf73d..880269c 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -9,6 +9,9 @@ from DateTime import DateTime from urllib import quote as url_quote +from zope.i18n import translate +from zope.i18nmessageid import Message + from zope.component import createObject, queryUtility from zope.interface import alsoProvides @@ -45,6 +48,17 @@ try: except ImportError: # pragma: no cover HAS_WRAPPED_FORM = False +COMMENT_DESCRIPTION_PLAIN_TEXT = _( + u"comment_description_plain_text", + default=u"You can add a comment by filling out the form below. " + + "Plain text formatting.") + +COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _( + u"comment_description_intelligent_text", + default=u"You can add a comment by filling out the form below. " + + "Plain text formatting. Web and email addresses are transformed " + + "into clickable links.") + class CommentForm(extensible.ExtensibleForm, form.Form): @@ -274,6 +288,20 @@ class CommentsViewlet(ViewletBase): conversation = IConversation(context) return conversation.enabled() + def comment_transform_message(self): + """Returns the description that shows up above the comment text, + dependent on the text_transform setting of the discussion control + panel. + """ + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings, check=False) + + if settings.text_transform == "text/x-web-intelligent": + message = translate(Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT)) + else: + message = translate(Message(COMMENT_DESCRIPTION_PLAIN_TEXT)) + return message + def has_replies(self, workflow_actions=False): """Returns true if there are replies. """ diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index a3bdb8a..e5b1875 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -284,6 +284,27 @@ class TestCommentsViewlet(PloneTestCase): portal_discussion.overrideDiscussionFor(self.portal.doc1, True) # Test if discussion has been enabled self.failUnless(self.viewlet.is_discussion_allowed()) + + def test_comment_transform_message(self): + # Default transform is plain/text + self.failUnless(self.viewlet.comment_transform_message()) + self.assertEquals( + self.viewlet.comment_transform_message(), + "You can add a comment by filling out the form below. Plain text " + + "formatting.") + + # Set text transform to intelligent text + registry = queryUtility(IRegistry) + settings = registry.forInterface(IDiscussionSettings, check=False) + settings.text_transform = "text/x-web-intelligent" + + # Make sure the comment description is changes accordingly + self.assertEquals( + self.viewlet.comment_transform_message(), + "You can add a comment by filling out the form below. " + + "Plain text formatting. Web and email addresses are transformed " + + "into clickable links.") + def test_has_replies(self): self.assertEquals(self.viewlet.has_replies(), False)