[Zope] copy/paste problem with dtml
Brian Lloyd
Brian@digicool.com
Tue, 4 Apr 2000 12:20:54 -0400
> It appears to be a common problem and noone has yet come up
> with an answer.
> Maybe someone from DC could explain what is wrong with the
> cut/paste code or
> point out what we are all doing wrong.
>
> Once I find an answer I will write a HowTo so that others
> don't bash thier
> heads against this like I have for the last week.
Hi guys,
I think that what you are running into is the fact that
cut/copy and paste originated as a through-the-web only
operation. It stored object references in the "clipboard",
which is really just a cookie containing the serialized
object references. Of course, this won't work if you
try to use cut/paste programmatically all within the
same request - the manage_pasteObjects method will look
for the "clipboard" cookie and fail to find it (and then
blow up). This is, in fact, what the "no clipboard data
found" message you are seeing means.
Luckily, there is a way to do it programmatically - you
just need to modify your code a little bit because you
have to manage the "clipboard data" yourself.
First, lets look at the behavior of manage_copyObjects. Its
signature is:
manage_copyObjects(self, ids, REQUEST=None, RESPONSE=None)
If you call manage_copyObjects and pass a REQUEST object, it
will assume that it is being called through the web and store
the clipboard data in the RESPONSE object of the passed in
REQUEST. If you do *not* pass a REQUEST, the method will
*return* the clipboard data to the caller. So the first change
we need to make is to save the result of calling manage_copyObjects.
Next, look at manage_pasteObjects:
manage_pasteObjects(self, cb_copy_data=None, REQUEST=None)
This method need *either* to get the "clipboard data" passed
in explicitly (as cb_copy_data), or to get it from a cookie
in the passed in REQUEST. Since we are doing this all in one
request, we'll need to pass the clipboard data in directly.
Note that there is currently a dependency on the REQUEST
being available in the current implementation (so that it
can determine whether you are allow to perform the paste),
so you'll need to pass in both the clip data and the REQUEST.
So here's an (untested) modification that should do what you
want - the only real difference is that we have to handle the
clip data explicitly.
<dtml-with Members>
<dtml-with "_.getitem(uname).content">
<dtml-call "REQUEST.set('my_clip_data',
manage_copyObjects(ids))">
</dtml-with>
<dtml-with "_.getitem(AUTHENTICATED_USER.getUserName()).content">
<dtml-call "manage_pasteObjects(my_clip_data, REQUEST)">
</dtml-with>
</dtml-with>
Hope this helps!
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com