[Zope] Programmatically deleting objects

Lennart Regebro regebro at nuxeo.com
Wed Mar 24 18:34:29 EST 2004


From: "Horak, Karl" <KEHORAK at 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?





More information about the Zope mailing list