Dynamically show the comment formatting message dependent on the text transform setting.

svn path=/plone.app.discussion/trunk/; revision=46035
This commit is contained in:
Timo Stollenwerk 2010-11-29 22:42:20 +00:00
parent ea2ff81b43
commit 0c94707743
4 changed files with 54 additions and 1 deletions

View File

@ -4,6 +4,10 @@ Changelog
1.0RC1 (unreleased) 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. - Description for text transform added to the discussion control panel.
[timo] [timo]

View File

@ -145,7 +145,7 @@
<fieldset> <fieldset>
<legend i18n:translate="label_add_comment">Add comment</legend> <legend i18n:translate="label_add_comment">Add comment</legend>
<p i18n:translate="description_add_comment"> <p tal:content="view/comment_transform_message">
You can add a comment by filling out the form below. Plain text You can add a comment by filling out the form below. Plain text
formatting. formatting.
</p> </p>

View File

@ -9,6 +9,9 @@ from DateTime import DateTime
from urllib import quote as url_quote 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.component import createObject, queryUtility
from zope.interface import alsoProvides from zope.interface import alsoProvides
@ -45,6 +48,17 @@ try:
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
HAS_WRAPPED_FORM = False 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): class CommentForm(extensible.ExtensibleForm, form.Form):
@ -274,6 +288,20 @@ class CommentsViewlet(ViewletBase):
conversation = IConversation(context) conversation = IConversation(context)
return conversation.enabled() 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): def has_replies(self, workflow_actions=False):
"""Returns true if there are replies. """Returns true if there are replies.
""" """

View File

@ -285,6 +285,27 @@ class TestCommentsViewlet(PloneTestCase):
# Test if discussion has been enabled # Test if discussion has been enabled
self.failUnless(self.viewlet.is_discussion_allowed()) 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): def test_has_replies(self):
self.assertEquals(self.viewlet.has_replies(), False) self.assertEquals(self.viewlet.has_replies(), False)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')