Reputation: 9041
I'm trying to return an objects state using the following code:
workflow = getToolByName(context,'portal_workflow')
status = workflow.getInfoFor(obj,'review_state')
When I try to output this using:
print "State: %s" % (status)
I get the following error:
Exception Type Workflow
Exception Exception Value No workflow provides '${name}' information.
I've done a little reading around the web but nothing seems to give a definitive answer.
Can anyone help?
EDIT This is not down to an object not having workflow. The object im trying to get the state for is using custom workflow. However switching this to using the default plone workflow still troughs the same error.
FIXED After just trying the simplest thing out:
status = obj.review_state
This works! go figure. Thanks anyway.
Moderators you can delete this post if you wish.
Upvotes: 4
Views: 1209
Reputation: 211
Actually, Giacomo's answer is correct. The obj
you were trying to pass to the getInfoFor
method is a catalog brain, not an actual content object. That is why asking for it's review_state
directly worked for you.
A Plone content object has no knowledge of it's own workflow state. That information is maintained by the workflow tool, which is why when you are looking at an actual content object you must use workflow_tool.getInfoFor
In your case, you've taken the result of a catalog search, which is a lightweight structure called a brain
, and tried to pass it to the workflow tool. Catalog brains do not have workflow, so the error you got is perfectly accurate. But a catalog brain does have a review_state
attribute, which corresponds to the review state of the object represented by the catalog brain.
In short, if you have a catalog brain, use brain.review_state
, if you have a content object, use workflow_tool.getInfoFor(obj, 'review_state')
Upvotes: 5
Reputation: 1879
In the variables tab of your definition (ZMI for portal_workflow), at the bottom of that page, make sure that state variable name is 'review_state' -- this may not be the default, IIRC. This may be one possible source of your problem.
Upvotes: 0
Reputation: 4496
That's because you are trying to get the workflow state of an object that doesn't have any associated workflow (probably a File or an Image). You can check in zmi->portal_workflows all of the contenttype-workflows pairings.
Upvotes: 2