[Zope-CMF] invokeFactory

Tres Seaver tseaver@zope.com
Fri, 07 Dec 2001 08:23:23 -0500


Brian Olsen wrote:

> I have a question.
> 
> Is it possible to call invokeFactory from an URL with extra parameters
> 
> Something like: 
> http://test.org/Members/Me/invokeFactory?id=Test&type_name=Link&remote_url=http://cmf.zope.org/ 


PortalFolder.invokeFactory and the construction machinery all
"forward" extra keyword arguments (positional ones too, but you
can't supply those via URL) to the underlying method called
to construct the instance.  Whether that constructor does the
Right Thing (tm) with them or not is a different matter.

In particular, Link.addLink *does* accept 'title',
'remote_url', and 'description' as additional parameters,
so your example ought to work.

*Later*  I just checked, and keyword arguments aren't passed
through to 'invokeFactory' by the publisher.  A workaround would
be to add a PythonScript, 'link_add', to your skin, and have it
accept optional 'remote_url', 'title', and 'description' arguments::

   ## Script (Python) "link_add"
   #title=Add a Link, including data
   #parameters=id,remote_url='',title='',description=''

   context.invokeFactory( type_name='Link'
                        , id=id
                        , remote_url=remote_url
                        , title=title
                        , description=description
                        )

   context.REQUEST['RESPONSE'].redirect( '%s/%s/metadata_edit_form'
     % ( context.absolute_url(), id ) )


Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com