Improve get_state to avoid errors

This commit is contained in:
Laurent Lasudry 2019-10-25 10:06:11 +02:00
parent 6aae162385
commit 7a2ed86ab4
1 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,8 @@ from zope.interface import providedBy
import random
import transaction
_marker = []
@required_parameters('container', 'type')
@at_least_one_of('id', 'title')
@ -266,19 +268,25 @@ def delete(obj=None):
@required_parameters('obj')
def get_state(obj=None):
def get_state(obj=None, default=_marker):
"""Get the current workflow state of the object.
:param obj: [required] Object that we want to get the state for.
:type obj: Content object
:returns: Object's current workflow state
:param default: Returned if no workflow is defined for the object.
:returns: Object's current workflow state, or `default`.
:rtype: string
:raises:
ValueError
Products.CMFCore.WorkflowCore.WorkflowException
:Example: :ref:`content_get_state_example`
"""
workflow = portal.get_tool('portal_workflow')
return workflow.getInfoFor(obj, 'review_state')
if default is not _marker and not workflow.getWorkflowsFor(obj):
return default
# This still raises WorkflowException when the workflow state is broken,
# ie 'review_state' is absent
return workflow.getInfoFor(ob=obj, name='review_state')
@required_parameters('obj', 'transition')