[Zope] Deleting a file in Python
Tim Nash
thedagdae at gmail.com
Sat Aug 25 15:05:38 EDT 2007
I had to go to the zope cookbook today to get this script so I thought
I'd paste it here for you as well. It may help you. It is from this
url: http://zopelabs.com/cookbook/1037768468
hth
Tim
##### to copy something from a folder
copy_info = some_folder.manage_copyObjects(('object_foo',
'object_bar',
'object_baz')
)
# The argument to manage_copyObjects is a tuple of object IDs which must exist
# in the folder where you call the method.
# The returned result is clipboard data, suitable for putting in a cookie.
# but we don't need cookies if we're copying and pasting in one
# script.
## If you WANT the clipboard in a cookie, maybe because you're
# going to paste it later in some other script, you need to
# pass in a REQUEST like so:
copy_info = some_folder.manage_copyObjects(('object_foo',
'object_bar',
'object_baz'),
REQUEST
)
# The cookie is set in REQUEST.RESPONSE.
#### To cut stuff from a folder
copy_info = some_folder.manage_cutObjects(('object_foo',
'object_bar',
'object_baz')
)
# ... it's just like manage_copyObjects
#### To delete things completely - no cut, no paste, just gone
some_folder.manage_delObjects(('object_foo',
'object_bar')
)
#### To paste the result of a cut or copy into a folder
some_other_folder.manage_pasteObjects(copy_info)
########## A complete copy / paste example
# get the source and destination parent folders
dest_base = context.restrictedTraverse('/foo/bar/baz')
src_base = context.restrictedTraverse('/fool/bear/booze')
folds = src_base.objectItems('Folder') # where the objects to copy live
for src_id, src_obj in folds:
# prepare the destination
try:
# we might have run the script already, or the destination
# might just exist already.
dest = getattr(dest_base, src_id)
print 'folder exists already',
except AttributeError:
# make sure the destination is there.
dest_base.manage_addProduct['OFSP'].manage_addFolder(src_id, '')
dest = getattr(dest, s_id)
print dest.absolute_url()
# now the real work, actually quite easy
try:
copy_info = src_obj.manage_copyObjects(('stylesheet_properties',))
print " copied...",
d.manage_pasteObjects(copy_info)
print "pasted!"
except:
print "...couldn't paste it there."
return printed
On 8/25/07, zozer at cercy.net <zozer at cercy.net> wrote:
> I'm reading the zope book, 2.6. And I've worked through the ZopeZoo
> tutorial in chapter 11. I want to make it possible to delete entries in
> the GuestBook via its web interface. It uses a python script to create the
> file with the line:
> context.manage_addProduct['OFSP'].manage_addFile(id,
> title="", file=comments)
>
> I assume I could write something like:
>
> context.manage_deleteProduct['OFSP'].manage_removeFile(id)
>
> or maybe:
>
> context.manage_addProduct['OFSP'].manage_deleteFile(id)
>
> but I can't figure out where context.* is documented.
>
>
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
More information about the Zope
mailing list