[Zope-dev] Cut/Copy/Paste objects programatically between folders
vmilitaru@sympatico.ca
vmilitaru@sympatico.ca
Tue, 31 Jul 2001 17:16:59 -0500
Hi,
Could someone give me a hint or "recipe" (better!) on how to use manage_cutObjects() and such. I am developing a Product which uses the Joust package for UI: I want my Product code to add/edit/move/delete objects programmatically inside the object hierarchy (inside the Joust folder). Is there an easier way than to use Zope's routines?
For example, I managed to import some pre-cooked package using Zope's manage_importObject():
---------------
from OFS.ObjectManager import ObjectManager
manage_addBarForm = PageTemplateFile("www/Bar_add", globals())
def manage_addBar(self, id, title, REQUEST=None):
"Create a Bar folder and add it to its parent's folder."
catalogus = Bar(id, title)
self._setObject(id,catalogus)
base_folder = getattr(self, id)
# import entire 'images/' folder in one sweep
base_folder.manage_importObject('images.zexp')
------------------
This is very practical: I can edit my objects using the ZMI, then make my Product import everything in one sweep. Also, if I want to add individual objects, I do:
------------------
from my_objects import *
base_folder._setObject('SomeObject', DTMLDocument(SomeObject, __name__='SomeObject')) # created an Object inside my base folder
or
base_folder._setObject('images2', MyFolder(id, title)) # # created a folder inside my base folder
then
images_folder = getattr(base_folder, 'images2')
images_folder._setObject('JPGs', MyFolder(id, title)) # this creates a folder inside a folder inside a folder, a.k.a a hierarchy.
-----------------
But now I want to cut/copy/paste/delete objects between my different folders. My guess is that I need to import CopyContainer:
-------------------
from OFS.CopySupport import CopyContainer
-------------------
But then what? How do I use manage_cutObjects() for example? Let's say, using the previous example, that I want to cut&paste 'SomeObject' from 'base_folder' and paste it into the 'JPGs' folder.
Regards - Vio