add optional workflow actions to the get_replies method of the comments viewlet.

switch from Acquisition.explicit to Acquisition.implicit for the comment class.
adjust test_comment to work with Acquisition.implicit.

svn path=/plone.app.discussion/trunk/; revision=27406
This commit is contained in:
Timo Stollenwerk 2009-06-13 16:46:37 +00:00
parent 24997f4eb9
commit 8fb254f73d
6 changed files with 55 additions and 34 deletions

View File

@ -1,8 +1,9 @@
<tal:block define="userHasReplyPermission view/can_reply; <tal:block define="userHasReplyPermission view/can_reply;
isDiscussionAllowed view/is_discussion_allowed; isDiscussionAllowed view/is_discussion_allowed;
isAnonymousDiscussionAllowed view/anonymous_discussion_allowed; isAnonymousDiscussionAllowed view/anonymous_discussion_allowed;
replies view/get_replies;
isAnon view/is_anonymous; isAnon view/is_anonymous;
canManage view/can_manage;
replies python:view.get_replies(canManage);
showCommenterImage view/show_commenter_image; showCommenterImage view/show_commenter_image;
errors options/state/getErrors|nothing;" errors options/state/getErrors|nothing;"
tal:condition="isDiscussionAllowed" tal:condition="isDiscussionAllowed"
@ -102,7 +103,7 @@
action="" action=""
method="get" method="get"
style="display: inline;" style="display: inline;"
tal:repeat="action reply_dict/actions" tal:repeat="action python:view.get_workflow_actions(reply)"
tal:attributes="action string:${reply/absolute_url}/content_status_modify; tal:attributes="action string:${reply/absolute_url}/content_status_modify;
name action/id"> name action/id">
<input type="hidden" name="workflow_action" tal:attributes="value action/id" /> <input type="hidden" name="workflow_action" tal:attributes="value action/id" />

View File

@ -8,7 +8,7 @@ from zope.component import createObject, getMultiAdapter, queryUtility
from zope.viewlet.interfaces import IViewlet from zope.viewlet.interfaces import IViewlet
from Acquisition import aq_inner, aq_parent from Acquisition import aq_inner, aq_parent, aq_base
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
@ -21,7 +21,7 @@ from plone.registry.interfaces import IRegistry
from plone.app.layout.viewlets.common import ViewletBase from plone.app.layout.viewlets.common import ViewletBase
from plone.app.discussion.interfaces import IComment, IReplies, IDiscussionSettings from plone.app.discussion.interfaces import IConversation, IComment, IReplies, IDiscussionSettings
from plone.app.discussion.conversation import conversationAdapterFactory from plone.app.discussion.conversation import conversationAdapterFactory
from plone.app.discussion.comment import CommentFactory from plone.app.discussion.comment import CommentFactory
@ -60,14 +60,28 @@ class CommentsViewlet(ViewletBase):
conversation = conversationAdapterFactory(self.context) conversation = conversationAdapterFactory(self.context)
return conversation.enabled return conversation.enabled
def get_replies(self): def get_replies(self, workflow_actions=False):
# Return all direct replies
conversation = conversationAdapterFactory(self.context)
# Acquisition wrap the conversation
context = aq_inner(self.context)
conversation = IConversation(context)
conversation = IConversation(context).__of__(context)
# Return all direct replies
if conversation.total_comments > 0: if conversation.total_comments > 0:
if workflow_actions:
# Return dict with workflow actions
#context = aq_inner(self.context)
wf = getToolByName(context, 'portal_workflow')
for r in conversation.getThreads():
comment_obj = r['comment']
actions = wf.listActionInfos(object=comment_obj)
return conversation.getThreads() return conversation.getThreads()
else: else:
return False return conversation.getThreads()
else:
return []
def get_commenter_home_url(self, username): def get_commenter_home_url(self, username):
if username is None: if username is None:

View File

@ -4,7 +4,7 @@ from datetime import datetime
from zope.interface import implements from zope.interface import implements
from zope.component.factory import Factory from zope.component.factory import Factory
from Acquisition import Explicit from Acquisition import Implicit
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from AccessControl.Owned import Owned from AccessControl.Owned import Owned
@ -14,7 +14,7 @@ from plone.app.discussion.interfaces import IComment
from Products.CMFCore.DynamicType import DynamicType from Products.CMFCore.DynamicType import DynamicType
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
class Comment(DynamicType, Traversable, RoleManager, Owned, Explicit): class Comment(DynamicType, Traversable, RoleManager, Owned, Implicit):
"""A comment. """A comment.
This object attempts to be as lightweight as possible. We implement a This object attempts to be as lightweight as possible. We implement a

View File

@ -143,7 +143,7 @@ class Conversation(Traversable, Persistent, Explicit):
def recurse(comment_id, d=0): def recurse(comment_id, d=0):
# Yield the current comment before we look for its children # Yield the current comment before we look for its children
yield {'id': comment_id, 'comment': self._comments[comment_id], 'depth': d} yield {'id': comment_id, 'comment': self[comment_id], 'depth': d}
# Recurse if there are children and we are not out of our depth # Recurse if there are children and we are not out of our depth
if depth is None or d + 1 < depth: if depth is None or d + 1 < depth:

View File

@ -56,7 +56,7 @@ class CommentTest(PloneTestCase):
self.assertEquals('Comment 1', comment.title) self.assertEquals('Comment 1', comment.title)
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath()) self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath())
self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault/' + str(new_comment1_id), comment.absolute_url()) self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_comment1_id), comment.absolute_url())
def test_workflow(self): def test_workflow(self):
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('simple_publication_workflow,')) self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('simple_publication_workflow,'))

View File

@ -541,8 +541,14 @@ class ConversationTest(PloneTestCase):
# Create a conversation. # Create a conversation.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
# Pretend that we have traversed to the comment by aq wrapping it.
conversation = conversation.__of__(self.portal.doc1)
# Check the parent # Check the parent
self.failUnless(conversation.__parent__) self.failUnless(conversation.__parent__)
self.failUnless(aq_parent(conversation))
# Todo: This one is failing!
#self.failUnless(conversation.REQUEST)
self.assertEquals(conversation.__parent__.getId(), 'doc1') self.assertEquals(conversation.__parent__.getId(), 'doc1')
def test_discussion_item_not_in_bad_types(self): def test_discussion_item_not_in_bad_types(self):