Using plone.api.content.transition

Hi everyone. I am developing an add-on, and I am trying to use Plone's api.content.transition method. However, I get an error.

Here is what I am trying to do, per the documentation here:

from plone import api
from plone.app.testing import SITE_OWNER_NAME

page = api.content.create(
    container=self.portal,
    type='Document',
    id='test-page',
    creator=SITE_OWNER_NAME,
    title='Test Page',
    )
api.content.transition(page, transition='publish')

I am running this code in a Unit Test logged in as SITE_OWNER_NAME. Here is the error I receive:

InvalidParameterError: Invalid transition 'publish'.
Valid transitions are:

What can I do to make my add-on recognize 'publish' as a valid transition?

Lastly, as an unrelated-to-my-error side question, what other transitions exist (e.g. what is the string associated with the Published->Private transition)? Is there a place in the documentation that lists them all?

Thanks in advance!

There seem to be no transitions for your content in its current state.
Could you check that you see transitions in the Plone UI?
Cheers!

There seem to be no transitions for your content in its current state.
Could you check that you see transitions in the Plone UI?
Cheers!

Do you mean whether I can make standard pages Published? I can certainly do that on my Plone site.

(obj=page , transition='publish')
...

Is the syntax, I think

when running tests you don't have a workflow associated with your content types by default; add the following line at the end of your setUpPloneSite() method:

def setUpPloneSite(self, portal):
    ...
    portal.portal_workflow.setDefaultChain('simple_publication_workflow')

for a working example check the code of collective.nitf.

2 Likes

@hvelarde Thank you, that worked! Is simple_publication_workflow the only available keyword? I noticed in my Plone site UI I can "Retract" things that have been published, yet the only apparently supported transitions under simple_publication_workflow seem to be 'publish' and 'submit'. Is there a way to add the transition associated with "Retracting" content?

I apologize for my questions if they are trivial; I am still new to Plone.

Edit: The reason I ask is because I get the following output when trying to use transition='retract':

InvalidParameterError: Invalid transition 'retract'.
Valid transitions are:
publish
submit

Edit 2: I am an idiot. I just had to publish the content before I could retract it. Thanks for the help everyone, I think I've got it figured out now.

1 Like