summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaurent Lasudry <lasudry@gmail.com>2019-10-25 08:06:11 (GMT)
committerLaurent Lasudry <lasudry@gmail.com>2019-10-25 08:06:11 (GMT)
commit7a2ed86ab4821129f7f3b6c816bc1cba2f12ee56 (patch)
tree9aff78bd1b76161b549aba5d2cfcdf0e44a8a46f /src
parent6aae1623856192860d8966efafb24dc4dc7ea718 (diff)
downloadplone.api-master.zip
plone.api-master.tar.gz
plone.api-master.tar.bz2
Improve get_state to avoid errorsHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/plone/api/content.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/plone/api/content.py b/src/plone/api/content.py
index dcdcbf6..745ffee 100644
--- a/src/plone/api/content.py
+++ b/src/plone/api/content.py
@@ -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')