RE: How to delete an object given a path in Zope
Hi Suresh, I've actually tried that. The problem I run into is that the folder in my path contains a dash. When I call manage_delObjects on the following: obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') id = obj.getId() context.webcasts.courses.2005-2006.manage_delObjects(id) Python complains about the '-' in 2005-2006 on the third line. So my thought was that if you had the object reference you could somehow delete that reference like so: obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') id = obj.getId() obj.manage_delObjects(id) This however does not work. It gives the following error: Error Type AttributeError Error Value temp Side note: I'm running Zope 2.7.6 Thanks, Mike -----Original Message----- From: suresh [mailto:suresh_vv@yahoo.com] Sent: Wednesday, March 15, 2006 3:09 AM To: Takahashi, Michael Subject: Re: How to delete an object given a path in Zope
Takahashi, Michael wrote:
I am trying to figure out how to delete an object in Zope given a
path.
<snip>
Any help is greatly appreciated.
You want to call manage_delObjects on the parent folder and give it the list of ids.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Takahashi, Michael wrote:
Hi Suresh,
I've actually tried that. The problem I run into is that the folder in my path contains a dash. When I call manage_delObjects on the following:
obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') id = obj.getId() context.webcasts.courses.2005-2006.manage_delObjects(id)
Python complains about the '-' in 2005-2006 on the third line. So my thought was that if you had the object reference you could somehow delete that reference like so:
obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') id = obj.getId() obj.manage_delObjects(id)
This however does not work. It gives the following error:
Error Type AttributeError Error Value temp
You need to get a reference to the container, and call 'manage_delObject' on it, e.g.: container = context.restrictedTraverse('webcasts/courses/2005-2006') container.manage_delObject('temp') Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEGEU8+gerLs4ltQ4RAqdkAJ98DJYKXeQShR9b/4wIDzo87+b8OACePtFV JL7HFDOImAsY981oadBlxys= =HQZA -----END PGP SIGNATURE-----
Tres Seaver wrote:
Takahashi, Michael wrote:
I've actually tried that. The problem I run into is that the folder in my path contains a dash. When I call manage_delObjects on the following:
obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp')
You need to get a reference to the container, and call 'manage_delObject' on it, e.g.:
container = context.restrictedTraverse('webcasts/courses/2005-2006') container.manage_delObject('temp')
I usually just call aq_parent obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') container = obj.aq_parent container.manage_delObject('temp') If you are deleting a list of objects in different folders you need to do a bit of tapdancing not to delete parents first. Like reverse sorting on the length of the physical path. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science Phone: +45 66 11 84 94 Mobile: +45 29 93 42 96
Takahashi, Michael wrote:
Hi Suresh,
I've actually tried that. The problem I run into is that the folder in my path contains a dash. When I call manage_delObjects on the following:
obj = context.restrictedTraverse('webcasts/courses/2005-2006/temp') id = obj.getId() context.webcasts.courses.2005-2006.manage_delObjects(id)
Try: context.webcasts.courses['2005-2006'].manage_delObjects(id) -- Thank you and Cheers, Suresh V. CTO, ParTecs, Bangalore http://www.partecs.com Plone-Zope-Python Consulting
participants (4)
-
Max M -
suresh -
Takahashi, Michael -
Tres Seaver