Patrick Downey
Patrick Downey

Reputation: 965

Plone/Dexterity- How can I get the "Title" of an object's workflow state?

I'm trying to get the "title" of the workflow state an object is in. I did try several things and I keep on getting the "id" of the workflow state.

One attempt that gets me the id

workflow = getToolByName(self.context,'portal_workflow')
status = workflow.getStatusOf("my_workflow", my_obj)
state = status["review_state"]
print state

Another attempt that also gave me an id

workflow = getToolByName(self.context,'portal_workflow')
status = workflow.getInfoFor(my_obj,'review_state')
#print type(status) returns "<type 'str'>"
print status

Another attempt:

state = api.content.get_state(obj=my_obj)
print state

How can I get the title of the state? There must be something simple I am missing.

Upvotes: 0

Views: 308

Answers (1)

Mathias
Mathias

Reputation: 6839

I assume you want to get the translated workflow state of an object. The state is usually translated within the plone i18n domain, so the plone UI shows your state properly. You can use zope.i18n.translate to get the translated state.

>>> workflow = getToolByName(my_obj,'portal_workflow')
>>> status = workflow.getInfoFor(my_obj,'review_state')

>>> from zope.i18n import translate
>>> translate(msgid=status, domain='plone', target_language='en')
>>> 'Published'

You may get the language from the language_tool.

Check http://zopei18n.readthedocs.org/en/latest/api.html#zope.i18n.translate for more Infos.

Upvotes: 5

Related Questions