has_replies function added to get only published comments for anon users. elro review fix. refs #9288
svn path=/plone.app.discussion/trunk/; revision=30252
This commit is contained in:
parent
6daa8824fb
commit
f0cbc787ab
@ -4,6 +4,7 @@
|
|||||||
isAnon view/is_anonymous;
|
isAnon view/is_anonymous;
|
||||||
canManage view/can_manage;
|
canManage view/can_manage;
|
||||||
replies python:view.get_replies(canManage);
|
replies python:view.get_replies(canManage);
|
||||||
|
has_replies python:view.has_replies(canManage);
|
||||||
showCommenterImage view/show_commenter_image;
|
showCommenterImage view/show_commenter_image;
|
||||||
errors options/state/getErrors|nothing;
|
errors options/state/getErrors|nothing;
|
||||||
wtool context/@@plone_tools/workflow"
|
wtool context/@@plone_tools/workflow"
|
||||||
@ -132,7 +133,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="reply"
|
<div class="reply"
|
||||||
tal:condition="python: isAnon and not isAnonymousDiscussionAllowed and replies">
|
tal:condition="python: isAnon and not isAnonymousDiscussionAllowed and has_replies">
|
||||||
<form tal:attributes="action view/login_action">
|
<form tal:attributes="action view/login_action">
|
||||||
<input class="standalone"
|
<input class="standalone"
|
||||||
style="margin-bottom: 1.25em;"
|
style="margin-bottom: 1.25em;"
|
||||||
|
@ -239,15 +239,35 @@ class CommentsViewlet(ViewletBase, layout.FormWrapper):
|
|||||||
conversation = IConversation(context)
|
conversation = IConversation(context)
|
||||||
return conversation.enabled()
|
return conversation.enabled()
|
||||||
|
|
||||||
|
def has_replies(self, workflow_actions=False):
|
||||||
|
"""Returns true if there are replies.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.get_replies(workflow_actions).next()
|
||||||
|
return True
|
||||||
|
except StopIteration:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_replies(self, workflow_actions=False):
|
def get_replies(self, workflow_actions=False):
|
||||||
|
"""Returns all replies to a content object.
|
||||||
|
|
||||||
|
If workflow_actions is false, only published
|
||||||
|
comments are returned.
|
||||||
|
|
||||||
|
If workflow actions is true, comments are
|
||||||
|
returned with workflow actions.
|
||||||
|
"""
|
||||||
context = aq_inner(self.context)
|
context = aq_inner(self.context)
|
||||||
conversation = IConversation(context)
|
conversation = IConversation(context)
|
||||||
|
|
||||||
def replies_with_workflow_actions():
|
|
||||||
# Return dict with workflow actions
|
|
||||||
#context = aq_inner(self.context)
|
|
||||||
wf = getToolByName(context, 'portal_workflow')
|
wf = getToolByName(context, 'portal_workflow')
|
||||||
|
|
||||||
|
# workflow_actions is only true when user
|
||||||
|
# has 'Manage portal' permission
|
||||||
|
|
||||||
|
def replies_with_workflow_actions():
|
||||||
|
# Generator that returns replies dict with workflow actions
|
||||||
for r in conversation.getThreads():
|
for r in conversation.getThreads():
|
||||||
comment_obj = r['comment']
|
comment_obj = r['comment']
|
||||||
# list all possible workflow actions
|
# list all possible workflow actions
|
||||||
@ -257,12 +277,22 @@ class CommentsViewlet(ViewletBase, layout.FormWrapper):
|
|||||||
r['actions'] = actions
|
r['actions'] = actions
|
||||||
yield r
|
yield r
|
||||||
|
|
||||||
|
def published_replies():
|
||||||
|
# Generator that returns replies dict with workflow status.
|
||||||
|
for r in conversation.getThreads():
|
||||||
|
comment_obj = r['comment']
|
||||||
|
workflow_status = wf.getInfoFor(comment_obj, 'review_state')
|
||||||
|
if workflow_status == 'published':
|
||||||
|
r = r.copy()
|
||||||
|
r['workflow_status'] = workflow_status
|
||||||
|
yield r
|
||||||
|
|
||||||
# Return all direct replies
|
# Return all direct replies
|
||||||
if conversation.total_comments > 0:
|
if conversation.total_comments > 0:
|
||||||
if workflow_actions:
|
if workflow_actions:
|
||||||
return replies_with_workflow_actions()
|
return replies_with_workflow_actions()
|
||||||
else:
|
else:
|
||||||
return conversation.getThreads()
|
return published_replies()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user