Skip to content
Browse files

Make comments and controlpanel views more robust, so they don't break…

… if no workflow is assigned to the 'Discussion Item' content type.
  • Loading branch information...
1 parent 36eb768 commit 910f75aa7e3f98e4467ea5e3aec89765a95af9cf Timo Stollenwerk committed
View
8 CHANGES.txt
@@ -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
2 plone/app/discussion/browser/comments.pt
@@ -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
18 plone/app/discussion/browser/comments.py
@@ -310,14 +310,16 @@ def comment_transform_message(self):
# 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
34 plone/app/discussion/browser/controlpanel.py
@@ -99,7 +99,7 @@ def settings(self):
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 @@ def settings(self):
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 @@ def settings(self):
# 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 @@ def custom_comment_workflow_warning(self):
"""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

0 comments on commit 910f75a

Please sign in to comment.
Something went wrong with that request. Please try again.