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 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) 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); author_home_url python:view.get_commenter_home_url(username=reply.author_username);
has_author_link python:author_home_url and not isAnon; has_author_link python:author_home_url and not isAnon;
portrait_url python:view.get_commenter_portrait(reply.author_username); 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); tal:attributes="class python:'comment replyTreeLevel'+str(depth)+' state-'+str(review_state);
style string:margin-left: ${depth}em; style string:margin-left: ${depth}em;
id string:${reply/getId}" id string:${reply/getId}"

View File

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

View File

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