get_commenter_portrait and get_commenter_home_url methods added to comments viewlet.
tests for get_commenter_portrait added. svn path=/plone.app.discussion/trunk/; revision=27349
This commit is contained in:
parent
dada11c43c
commit
1af2b435fd
@ -26,16 +26,16 @@
|
||||
tal:define="reply reply_dict/comment;
|
||||
depth reply_dict/depth|python:0;
|
||||
creator reply/Creator;
|
||||
author_home_url string:${context/portal_url}/author/${reply/author_username};
|
||||
portrait python: here.portal_membership.getPersonalPortrait(reply.author_username);
|
||||
commenter_home_url python:view.get_commenter_home_url(reply.author_username);
|
||||
portrait python:view.get_commenter_portrait(reply.author_username);
|
||||
anonymous_creator python:creator in ('Anonymous User', '');"
|
||||
tal:attributes="class python:'comment replyTreeLevel'+str(depth);
|
||||
style string:margin-left: ${depth}em;
|
||||
id string:comment-${reply/id}">
|
||||
|
||||
<div class="commentImage" tal:condition="not:anonymous_creator">
|
||||
<a href="" tal:condition="not:isAnon"
|
||||
tal:attributes="href author_home_url">
|
||||
<a href="" tal:condition="python: commenter_home_url and not isAnon"
|
||||
tal:attributes="href commenter_home_url">
|
||||
<img src="defaultUser.gif"
|
||||
alt=""
|
||||
border="0"
|
||||
@ -47,7 +47,7 @@
|
||||
alt=""
|
||||
border="0"
|
||||
width="75"
|
||||
tal:condition="isAnon"
|
||||
tal:condition="python: isAnon or not commenter_home_url"
|
||||
tal:attributes="src portrait/absolute_url;
|
||||
alt reply/creator" />
|
||||
</div>
|
||||
@ -64,7 +64,7 @@
|
||||
<a href=""
|
||||
tal:condition="not:isAnon"
|
||||
tal:content="creator"
|
||||
tal:attributes="href author_home_url">
|
||||
tal:attributes="href commenter_home_url">
|
||||
Poster Name
|
||||
</a>
|
||||
<span tal:condition="isAnon"
|
||||
|
@ -67,6 +67,19 @@ class CommentsViewlet(ViewletBase):
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_commenter_home_url(self, username):
|
||||
if username is None:
|
||||
return None
|
||||
else:
|
||||
return "%s/author/%s" % (self.context.portal_url(), username)
|
||||
|
||||
def get_commenter_portrait(self, username):
|
||||
|
||||
if username is None:
|
||||
return None
|
||||
else:
|
||||
return self.portal_membership.getPersonalPortrait(username);
|
||||
|
||||
def is_anonymous(self):
|
||||
return self.portal_state.anonymous()
|
||||
|
||||
@ -78,7 +91,7 @@ class CommentsViewlet(ViewletBase):
|
||||
return time.strftime("%a, %d %b %Y %H:%M")
|
||||
# XXX: Not working, returns None !!!
|
||||
#return self.context.restrictedTraverse('@@plone').toLocalizedTime(time, long_format=True)
|
||||
|
||||
|
||||
class AddComment(BrowserView):
|
||||
"""Add a comment to a conversation
|
||||
"""
|
||||
|
@ -7,9 +7,13 @@ from zope.component import createObject
|
||||
|
||||
from Acquisition import aq_base, aq_parent, aq_inner
|
||||
|
||||
from OFS.Image import Image
|
||||
|
||||
from plone.app.vocabularies.types import BAD_TYPES
|
||||
|
||||
from Products.CMFCore.FSImage import FSImage
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from Products.CMFPlone.tests import dummy
|
||||
from Products.PloneTestCase.ptc import PloneTestCase
|
||||
|
||||
from plone.app.discussion.browser.comments import CommentsViewlet
|
||||
@ -22,11 +26,12 @@ class CommentsViewletTest(PloneTestCase):
|
||||
layer = DiscussionLayer
|
||||
|
||||
def afterSetUp(self):
|
||||
# First we need to create some content.
|
||||
self.loginAsPortalOwner()
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None)
|
||||
self.membership_tool = getToolByName(self.folder, 'portal_membership')
|
||||
self.memberdata = self.portal.portal_memberdata
|
||||
request = self.app.REQUEST
|
||||
context = getattr(self.portal, 'doc1')
|
||||
self.viewlet = CommentsViewlet(context, request, None, None)
|
||||
@ -35,12 +40,53 @@ class CommentsViewletTest(PloneTestCase):
|
||||
pass
|
||||
|
||||
def test_get_commenter_portrait(self):
|
||||
|
||||
# Add a user with a member image
|
||||
self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
|
||||
self.memberdata._setPortrait(Image(id='jim', file=dummy.File(), title=''), 'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').getId(), 'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').meta_type, 'Image')
|
||||
|
||||
# Add a conversation with a comment
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
conversation = conversation.__of__(self.portal.doc1)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
comment.Creator = 'Jim'
|
||||
comment.author_username = 'jim'
|
||||
new_id = conversation.addComment(comment)
|
||||
|
||||
# Call get_commenter_portrait method of the viewlet
|
||||
self.viewlet.update()
|
||||
self.viewlet.get_commenter_portrait('Foo')
|
||||
portrait = self.viewlet.get_commenter_portrait('jim')
|
||||
|
||||
# Check if the correct member image is returned
|
||||
self.assert_(isinstance(portrait, Image))
|
||||
self.assertEquals(portrait.absolute_url(), 'http://nohost/plone/portal_memberdata/portraits/jim')
|
||||
|
||||
def test_get_commenter_portrait_without_userimage(self):
|
||||
|
||||
# Create a user without a user image
|
||||
pass
|
||||
self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
|
||||
|
||||
# Add a conversation with a comment
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
conversation = conversation.__of__(self.portal.doc1)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
comment.Creator = 'Jim'
|
||||
comment.author_username = 'jim'
|
||||
new_id = conversation.addComment(comment)
|
||||
|
||||
# Call get_commenter_portrait method of the viewlet
|
||||
self.viewlet.update()
|
||||
portrait = self.viewlet.get_commenter_portrait('jim')
|
||||
|
||||
# Check if the correct default member image is returned
|
||||
self.assert_(isinstance(portrait, FSImage))
|
||||
self.assertEquals(portrait.absolute_url(), 'http://nohost/plone/defaultUser.gif')
|
||||
|
||||
def test_get_commenter_home(self):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user