Trying to show the state of an object in plone gives "No workflow" provides the information "$ {name}". error

I am trying to return the state of objects using the following code:

workflow = getToolByName(context,'portal_workflow') status = workflow.getInfoFor(obj,'review_state') 

When I try to execute the output using:

 print "State: %s" % (status) 

I get the following error:

Exception type workflow

Exception Exception Meaning No workflow provides the information "$ {name}".

I read a little on the Internet, but nothing gives a definitive answer.

Can anyone help?

EDIT This does not apply to an object that does not have a workflow. The im object trying to get state for uses a user workflow. However, switching this to using the plone workflow still causes the same error.

Fixed Just try the simplest thing:

status = obj.review_state

It works! go figure. Anyway, thanks.

Moderators, you can delete this post if you want.

+4
source share
3 answers

Actually, Giacomo's answer is correct. obj you tried to pass to the getInfoFor method is the brain of the directory, not the actual content object. This is why the review_state query directly worked for you.

The Plone content object does not know its own workflow state. This information is maintained by the workflow tool, so when you look at the actual content object, you should use workflow_tool.getInfoFor

In your case, you took a search result from a directory, which is a lightweight structure called a brain , and tried to pass it on to a workflow tool. The brains of the catalog do not have a workflow, so the error you received is absolutely accurate. But the catalog brain has the 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')

+5
source

This is because you are trying to get the state of a workflow for an object that does not have a workflow associated with it (possibly a file or image). You can check in zmi-> portal_workflow all contenttype-workflows pairs.

+2
source

On the variable tab of your definition (ZMI for portal_workflow) at the bottom of this page, make sure the name of the status variable is "review_state" - this cannot be the default value, IIRC. This may be one of the possible sources of your problem.

0
source

Source: https://habr.com/ru/post/1381885/


All Articles