[Zope] Programmatically deleting objects
Chris Withers
lists at simplistix.co.uk
Thu Mar 25 04:53:12 EST 2004
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
More information about the Zope
mailing list