[Zope] Re: How best to copy and paste in pythonscript?
Tres Seaver
tseaver at palladion.com
Mon Aug 28 10:29:17 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Gaute Amundsen wrote:
> On Monday 28 August 2006 12:21, Andreas Jung wrote:
>> --On 28. August 2006 12:08:16 +0200 Gaute Amundsen <gaute at div.org> wrote:
>>> Hi.
>>>
>>> I am having some strange problems getting copy and paste to work
>>> propperly in python script
>>>
>>> Basically I do:
>>>
>>> parent.manage_copyObjects([currFold.id], REQUEST)
>>>
>>> in one script, and:
>>>
>>> dest_fold.manage_pasteObjects(REQUEST)
>> You must check the APIs carefully. manage_pasteObjects()
>> takes REQUEST as keyword parameter but not as positional
>> parameter. So you must pass is it as keyword parameter!
>>
>> -aj
>
> So you are saying that
>
> parent.manage_copyObjects([currFold.id], REQUEST)
>
> is ok. and
>
> dest_fold.manage_pasteObjects(REQUEST=context.REQUEST)
>
> should be ok?
>
> When you mention it, where exactly is the APIs?
> A search of the zope site for "manage_copyObjects" givs me two largely
> irrelevant hits.
>
> Looking at this for example:
> http://docs.neuroinf.de/api/plone-api/public/OFS.CopySupport.CopyContainer-class.html
> ( which is one of the first things google throws up )
>
> gives no indication that REQUEST is a keyword parameter.
I think the keyword argument bit is a red herring. The issue here is
that the methods you are calling are not really designed to be scripted
within the context of a single request: 'manage_copyObjects' sets a
cookie in the *response* object, while 'manage_pasteObjects' looks for
that cookie in the *request* object. This works fine when used as
designed: the cookie from the response gets sent back in the next
request, which can then figure out which object(s) to paste.
For scripting, you need to capture the result of calling
'manage_copyObjects', which will be the value of the cookie (the
"clipboard data"), and then pass it into 'manage_pasteObjects'. E.g.::
cb_data = source.manage_copyObjects(ids=selected)
target.manage_pasteObjects(cb_data)
In this mode, you don't (and shouldn't) need to pass the request at all.
Tres.
- --
===================================================================
Tres Seaver +1 202-558-7113 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE8v29+gerLs4ltQ4RAqQzAKCkSdXNdseAPoXcgRfMlUzMFq76nQCgnXPM
sRYlTXImfZ3vEPfVBej4hvo=
=6Fdy
-----END PGP SIGNATURE-----
More information about the Zope
mailing list