RE: [Zope] Programmatically deleting objects
Chris, I've given up on using the ZMI's system of checkboxes named with object ids and calling the manage_delObjects:method from a submit button. Instead I'm now simply generating a URL that passes a querystring with the path to the item and the item name: <A HREF="goDelete?item=<dtml-var id>&delPath=<dtml-var expr="aq_parent.aq_parent.id">.<dtml-var expr="aq_parent.id">"> Thus, I have two variables, delPath = 'ORDlibrary.BC' (or whichever subfolder) is the container of the item to be deleted, item = 'filename.ext', which is the object's id. The goDelete method is some variation on: <dtml-call expr="REQUEST.delPath.manage_delObjects([REQUEST.item])"> (This generates an AttributeError stating 'str' object has no attribute 'manage_delObjects') Or: <dtml-call expr="_.getitem(REQUEST.delPath).manage_delObjects([REQUEST.item])"> (This generates a KeyError with an Error Value of 'ORDlibrary.BC') The odd thing is that using explicit strings as you pointed out in your suggestion works fine: <dtml-call expr="ORDlibrary.BC.manage_delObjects([REQUEST.item])"> Why are literals working but not variables with string values? Finally, I've tried building the HREF as <A HREF="req?item=<dtml-var id>&delPathA=<dtml-var expr="aq_parent.aq_parent.id">&delPathB=<dtml-var expr="aq_parent.id">">, where goDelete now looks like: <dtml-call expr="_.getitem(REQUEST.delPathA)._.getitem(REQUEST.delPathB).manage_delObje cts([REQUEST.item])"> This repeatedly asks for user ID and password (BTW, goDelete has its proxy value set to Manager). This is the equivalent of the "spinning Zope" in my initial message. When my server admin captured the 8080 packets, we saw that the system was sending nothing acceptable for user ID/password and then generating a 401 error and repeating this process infinitely. Since this occurs on my standalone development machine as well as the firewall-Zope server production environment, it doesn't appear to be a virtual host/proxy passing problem. That said, I find that calls to SquishDot management functions and Zope manage_editProperties work on my testbed but not when they are moved onto the firewalled system. But that problem is for another day. Thanks in advance, Karl -----Original Message----- From: Chris Withers [mailto:lists@simplistix.co.uk] Sent: Wednesday, March 24, 2004 6:32 AM To: Horak, Karl; zope@zope.org Subject: Re: [Zope] Programmatically deleting objects (keep replies on the list) Horak, Karl wrote:
I think that Zope isn't correctly finding my target item and keeps calling manage_delObjects until the parameter list is empty, which never happens.
What's your evidence for this?
For an item that is not in the same folder as my method for deletion, is the correct syntax:
/ORDweb/ORDlibrary/BC.manage_delObjects(ids) (where ids is a list of a single object id) or /ORDweb/ORDlibrary/BC.manage_delObjects(/ORDweb/ORDlibrary/BC/ids) or something else?
if ids contains the ids of items you want to delete, and those items are contained in BC, then you want: ORDweb.ORDlibrary.BC.manage_delObjects(ids) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
From: "Horak, Karl" <KEHORAK@sandia.gov>
<A HREF="goDelete?item=<dtml-var id>&delPath=<dtml-var expr="aq_parent.aq_parent.id">.<dtml-var expr="aq_parent.id">">
<dtml-call expr="REQUEST.delPath.manage_delObjects([REQUEST.item])"> (This generates an AttributeError stating 'str' object has no attribute 'manage_delObjects')
Yes, delPath is a request variable, and therefore a string. It seems to me that you want to delete the item that you are viewing, there "here" object, so to speak. All the information you need to identify which object that is, is the path. You can probably pass <dtml-var absolute_url> as the item. That should be enough. Possibly you need "absolute_url(relative=1)", I'm not sure.
<dtml-call expr="_.getitem(REQUEST.delPath).manage_delObjects([REQUEST.item])">
I don't seem why you call an DTML method to run python code. Use a python script instead. In the pythonscript youshould be able to use restricted traverse to find the object item, get it's aq_parent, and call manage_delObjects on it. However, even this is total overkill. :-) <A HREF="<dtml-var expr="aq_parent.absolute_url()+'myDeleteScript?item='+id">"> should give you a link pointing to http://foo.com/the/parent/object/myDeleteScript?item=objectid The myDeleteScript then simply calls context.manage_delObjects(item) That should do it. Do you really want to use DTML?
Horak, Karl wrote:
I've given up on using the ZMI's system of checkboxes named with object ids and calling the manage_delObjects:method from a submit button. Instead I'm now simply generating a URL that passes a querystring with the path to the item and the item name:
<A HREF="goDelete?item=<dtml-var id>&delPath=<dtml-var expr="aq_parent.aq_parent.id">.<dtml-var expr="aq_parent.id">">
That is truly horrible :-(
Thus, I have two variables, delPath = 'ORDlibrary.BC' (or whichever subfolder) is the container of the item to be deleted, item = 'filename.ext', which is the object's id.
The goDelete method is some variation on:
<dtml-call expr="REQUEST.delPath.manage_delObjects([REQUEST.item])"> (This generates an AttributeError stating 'str' object has no attribute 'manage_delObjects')
Or:
<dtml-call expr="_.getitem(REQUEST.delPath).manage_delObjects([REQUEST.item])"> (This generates a KeyError with an Error Value of 'ORDlibrary.BC')
The odd thing is that using explicit strings as you pointed out in your suggestion works fine: <dtml-call expr="ORDlibrary.BC.manage_delObjects([REQUEST.item])">
Urm, you need to learn some python... If you really insist on persuing this insane course, your code would need to be: <dtml-call expr="restrictedTraverse(REQUEST.delPath.replace('.','/')).manage_delObjects([REQUEST.item])"> God, I feel soiled just typing that :-(
Why are literals working but not variables with string values?
Because _.getitem is not restrictedTraverse, it just behaves like a simple python mapping. And even if it was restrictedTraverse, you have .'s where you need /'s.
This repeatedly asks for user ID and password
Hit cancel. Check out the error message. Maybe try VerboseSecurity.
value set to Manager). This is the equivalent of the "spinning Zope" in my initial message.
Zope is NOT spinning here!
That said, I find that calls to SquishDot management functions and Zope manage_editProperties work on my testbed but not when they are moved onto the firewalled system.
Eh? Right, here's a solution in ZPT. Put a ZPT in your ORDLibrary.BC folder called index_html: <html> <body> <form action="manage_delObjects"> <table> <tr tal:repeat="id here/objectIds"> <td> <input type="checkbox" name="ids:list" tal:attributes="value id"> </td> <td tal:contents="id"/> </tr> </table> <input type="submit"> </body> </html> Any problems? I suggest you really read the online Zope book :-S Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
Horak, Karl -
Lennart Regebro