[Zope-CMF] cmf - publish content
Tres Seaver
tseaver@zope.com
Mon, 10 Dec 2001 22:47:36 -0500
Alexander Keller wrote:
> Hi!
>
> I have the following problem:
>
> I want to add a "Publish"-Button in my CMF because I'd like to publish
> more than one document, e.g. I want to select 10 documents to be
> published.
>
> I already found a nice function
>
> context.portal_workflow.doActionFor(obj[1],
> 'publish',comment='published by Bender')
>
> but I don't now how to pass the list with the selected elements.
Take a look at how the 'folder_contents' form is built:
it consists of checkboxes, one per content item, where
each box is named 'ids:list'. Zope marshalls *all* form
fields with the ':list' suffix into a single list, named
with the prefix (in this case, 'ids'). So, you would write
your function something like what 'folder_copy' does, e.g.::
## Script (Python) "folder_publish"
##title=Publish selected content
##parameters=
REQUEST=context.REQUEST
if REQUEST.has_key('ids'):
for id in ids:
obj = getattr( context, id )
context.portal_workflow.doActionFor(obj,
'publish',comment='published by Bender')
return REQUEST.RESPONSE.redirect(context.absolute_url()
+ '/folder_contents?portal_status_message=Item(s)+Published.')
else:
return REQUEST.RESPONSE.redirect(context.absolute_url()
+ '/folder_contents?portal_status_message='
+ 'Please+select+one+or+more+items+to+publish+first.')
Note that the action of the form in 'folder_contents' is the
'absolute_url' of the folder. How then does this list get passed
to your function? Notice the names of the various submit buttons
at the bottom of the form: each one has the ':method' suffix,
which signals Zope to dispatch the request to the corresponding
method of the same name. So, if you name your method
'folder_publish', you would add a button to your form::
<input type="submit" name="folder_publish:method"
value="Publish">
Hope that helps,
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com