Plain text to HTML transformation added for comment text
svn path=/plone.app.discussion/trunk/; revision=38898
This commit is contained in:
parent
5a379b7c4f
commit
35d7743b7a
@ -4,6 +4,9 @@ Changelog
|
||||
1.0b7 (unreleased)
|
||||
------------------
|
||||
|
||||
* Plain text to HTML transformation added for comment text.
|
||||
[timo]
|
||||
|
||||
* Rewrote all tal:condition in comments.pt. The authenticated user has
|
||||
the reply button and the comment form if he has the "Reply to item"
|
||||
permission And the discussion is currently allowed.
|
||||
|
@ -81,7 +81,7 @@
|
||||
</div>
|
||||
|
||||
<div class="commentBody"
|
||||
tal:content="reply/getText" />
|
||||
tal:content="structure python:view.cook(reply.getText())" />
|
||||
|
||||
<div class="commentActions">
|
||||
<button class="context reply-to-comment-button hide allowMultiSubmit"
|
||||
|
@ -173,9 +173,10 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
|
||||
comment_id = conversation.addComment(comment)
|
||||
|
||||
# If a user post a comment and moderation is enabled, a message is shown
|
||||
# to the user that his/her comment awaits moderation. If the user has manage
|
||||
# right, he/she is redirected directly to the comment.
|
||||
can_manage = getSecurityManager().checkPermission('Manage portal', context)
|
||||
# to the user that his/her comment awaits moderation. If the user has
|
||||
# manage right, he/she is redirected directly to the comment.
|
||||
can_manage = getSecurityManager().checkPermission('Manage portal',
|
||||
context)
|
||||
if wf.getChainForPortalType('Discussion Item') == \
|
||||
('comment_review_workflow',) and not can_manage:
|
||||
# Show info message when comment moderation is enabled
|
||||
@ -209,11 +210,22 @@ class CommentsViewlet(ViewletBase):
|
||||
|
||||
# view methods
|
||||
|
||||
def cook(self, text):
|
||||
transforms = getToolByName(self, 'portal_transforms')
|
||||
targetMimetype = 'text/html'
|
||||
mimetype = 'text/plain'
|
||||
return transforms.convertTo(targetMimetype,
|
||||
text,
|
||||
context=self,
|
||||
mimetype=mimetype).getData()
|
||||
|
||||
def can_reply(self):
|
||||
return getSecurityManager().checkPermission('Reply to item', aq_inner(self.context))
|
||||
return getSecurityManager().checkPermission('Reply to item',
|
||||
aq_inner(self.context))
|
||||
|
||||
def can_manage(self):
|
||||
return getSecurityManager().checkPermission('Manage portal', aq_inner(self.context))
|
||||
return getSecurityManager().checkPermission('Manage portal',
|
||||
aq_inner(self.context))
|
||||
|
||||
def is_discussion_allowed(self):
|
||||
context = aq_inner(self.context)
|
||||
@ -268,7 +280,7 @@ class CommentsViewlet(ViewletBase):
|
||||
r = r.copy()
|
||||
r['workflow_status'] = workflow_status
|
||||
yield r
|
||||
|
||||
|
||||
# Return all direct replies
|
||||
if conversation.total_comments > 0:
|
||||
if workflow_actions:
|
||||
@ -288,7 +300,9 @@ class CommentsViewlet(ViewletBase):
|
||||
# return the default user image if no username is given
|
||||
return 'defaultUser.gif'
|
||||
else:
|
||||
portal_membership = getToolByName(self.context, 'portal_membership', None)
|
||||
portal_membership = getToolByName(self.context,
|
||||
'portal_membership',
|
||||
None)
|
||||
return portal_membership.getPersonalPortrait(username).absolute_url();
|
||||
|
||||
def anonymous_discussion_allowed(self):
|
||||
@ -304,15 +318,23 @@ class CommentsViewlet(ViewletBase):
|
||||
return settings.show_commenter_image
|
||||
|
||||
def is_anonymous(self):
|
||||
portal_membership = getToolByName(self.context, 'portal_membership', None)
|
||||
portal_membership = getToolByName(self.context,
|
||||
'portal_membership',
|
||||
None)
|
||||
return portal_membership.isAnonymousUser()
|
||||
|
||||
def login_action(self):
|
||||
return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),)
|
||||
return '%s/login_form?came_from=%s' % (self.navigation_root_url,
|
||||
url_quote(self.request.get('URL', '')),)
|
||||
|
||||
def format_time(self, time):
|
||||
# We have to transform Python datetime into Zope DateTime
|
||||
# before we can call toLocalizedTime.
|
||||
util = getToolByName(self.context, 'translation_service')
|
||||
zope_time = DateTime(time.year, time.month, time.day, time.hour, time.minute, time.second)
|
||||
zope_time = DateTime(time.year,
|
||||
time.month,
|
||||
time.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
time.second)
|
||||
return util.toLocalizedTime(zope_time, long_format=True)
|
||||
|
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
|
||||
@ -106,6 +107,28 @@ class TestCommentsViewlet(PloneTestCase):
|
||||
context = getattr(self.portal, 'doc1')
|
||||
self.viewlet = CommentsViewlet(context, request, None, None)
|
||||
|
||||
def test_cook(self):
|
||||
text = """First paragraph
|
||||
|
||||
Second paragraph"""
|
||||
self.assertEquals(self.viewlet.cook(text),
|
||||
"<p>First paragraph<br /> <br /> Second paragraph</p>")
|
||||
|
||||
def test_cook_no_html(self):
|
||||
text = """<b>Got HTML?</b>"""
|
||||
self.assertEquals(self.viewlet.cook(text),
|
||||
"<p><b>Got HTML?</b></p>")
|
||||
|
||||
def test_cook_with_no_ascii_characters(self):
|
||||
text = """Umlaute sind ä, ö und ü."""
|
||||
self.assertEquals(self.viewlet.cook(text),
|
||||
"<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>")
|
||||
|
||||
def test_cook_links(self):
|
||||
text = "Go to http://www.plone.org"
|
||||
self.assertEquals(self.viewlet.cook(text),
|
||||
"<p>Go to http://www.plone.org</p>")
|
||||
|
||||
def test_can_reply(self):
|
||||
# Portal owner can reply
|
||||
self.failUnless(self.viewlet.can_reply())
|
||||
|
Loading…
Reference in New Issue
Block a user