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:
parent
36eb76869a
commit
910f75aa7e
@ -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)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
@ -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}"
|
||||||
|
@ -310,10 +310,12 @@ 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')
|
||||||
|
if workflow_chain:
|
||||||
|
comment_workflow = workflow_chain[0]
|
||||||
comment_workflow = wftool[comment_workflow]
|
comment_workflow = wftool[comment_workflow]
|
||||||
# check if the current workflow implements a pending state. If this is
|
# check if the current workflow implements a pending state. If this
|
||||||
# true comments are moderated
|
# is true comments are moderated
|
||||||
if 'pending' in comment_workflow.states:
|
if 'pending' in comment_workflow.states:
|
||||||
message = message + " " + \
|
message = message + " " + \
|
||||||
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED),
|
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED),
|
||||||
|
@ -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,10 +180,12 @@ 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:
|
||||||
|
workflow = workflow_chain[0]
|
||||||
|
if workflow == 'one_state_workflow':
|
||||||
settings.moderation_enabled = False
|
settings.moderation_enabled = False
|
||||||
elif wf == 'comment_review_workflow':
|
elif workflow == 'comment_review_workflow':
|
||||||
settings.moderation_enabled = True
|
settings.moderation_enabled = True
|
||||||
else:
|
else:
|
||||||
# Custom workflow
|
# Custom workflow
|
||||||
|
Loading…
Reference in New Issue
Block a user