Make comments and controlpanel views more robust, so they don't break if no workflow is assigned to the 'Discussion Item' content type.

This commit is contained in:
Timo Stollenwerk 2012-03-15 13:06:00 +01:00
parent 36eb76869a
commit 910f75aa7e
4 changed files with 37 additions and 25 deletions

View File

@ -1,6 +1,14 @@
Changelog
=========
2.1.5 (unreleased)
------------------
- Make comments and controlpanel views more robust, so they don't break if no
workflow is assigned to the 'Discussion Item' content type.
[timo]
2.1.4 (2012-02-29)
------------------

View File

@ -34,7 +34,7 @@
author_home_url python:view.get_commenter_home_url(username=reply.author_username);
has_author_link python:author_home_url and not isAnon;
portrait_url python:view.get_commenter_portrait(reply.author_username);
review_state python:wtool.getInfoFor(reply, 'review_state');"
review_state python:wtool.getInfoFor(reply, 'review_state', 'none');"
tal:attributes="class python:'comment replyTreeLevel'+str(depth)+' state-'+str(review_state);
style string:margin-left: ${depth}em;
id string:${reply/getId}"

View File

@ -310,14 +310,16 @@ class CommentsViewlet(ViewletBase):
# comment workflow
wftool = getToolByName(context, "portal_workflow", None)
comment_workflow = wftool.getChainForPortalType('Discussion Item')[0]
comment_workflow = wftool[comment_workflow]
# check if the current workflow implements a pending state. If this is
# true comments are moderated
if 'pending' in comment_workflow.states:
message = message + " " + \
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED),
context=self.request)
workflow_chain = wftool.getChainForPortalType('Discussion Item')
if workflow_chain:
comment_workflow = workflow_chain[0]
comment_workflow = wftool[comment_workflow]
# check if the current workflow implements a pending state. If this
# is true comments are moderated
if 'pending' in comment_workflow.states:
message = message + " " + \
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED),
context=self.request)
return message

View File

@ -99,7 +99,7 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
wftool = getToolByName(self.context, "portal_workflow", None)
wf = wftool.getChainForPortalType('Discussion Item')
workflow_chain = wftool.getChainForPortalType('Discussion Item')
output = []
# Globally enabled
@ -107,8 +107,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
output.append("globally_enabled")
# Comment moderation
if 'one_state_workflow' not in wf and \
'comment_review_workflow' not in wf:
if 'one_state_workflow' not in workflow_chain and \
'comment_review_workflow' not in workflow_chain:
output.append("moderation_custom")
elif settings.moderation_enabled:
output.append("moderation_enabled")
@ -125,9 +125,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
# Workflow
wftool = getToolByName(self.context, 'portal_workflow', None)
discussion_workflow = \
wftool.getChainForPortalType('Discussion Item')[0]
if discussion_workflow:
if workflow_chain:
discussion_workflow = workflow_chain[0]
output.append(discussion_workflow)
# Merge all settings into one string
@ -150,8 +149,9 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
"""Returns a warning string if a custom comment workflow is enabled.
"""
wftool = getToolByName(self.context, "portal_workflow", None)
wf = wftool.getChainForPortalType('Discussion Item')
if 'one_state_workflow' in wf or 'comment_review_workflow' in wf:
workflow_chain = wftool.getChainForPortalType('Discussion Item')
if 'one_state_workflow' in workflow_chain \
or 'comment_review_workflow' in workflow_chain:
return
return True
@ -180,11 +180,13 @@ def notify_configuration_changed(event):
if 'workflow' in event.data:
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
wf = wftool.getChainForPortalType('Discussion Item')[0]
if wf == 'one_state_workflow':
settings.moderation_enabled = False
elif wf == 'comment_review_workflow':
settings.moderation_enabled = True
else:
# Custom workflow
pass
workflow_chain = wftool.getChainForPortalType('Discussion Item')
if workflow_chain:
workflow = workflow_chain[0]
if workflow == 'one_state_workflow':
settings.moderation_enabled = False
elif workflow == 'comment_review_workflow':
settings.moderation_enabled = True
else:
# Custom workflow
pass