[Zope] Programmatically deleting objects

Horak, Karl KEHORAK at sandia.gov
Thu Mar 25 13:12:25 EST 2004


Chris,

I'm perfectly happy to toss the whole dtml mess overboard because it's so
awkward.  The only reason I went toward using this ridiculous querystring is
that a test case worked with literals and '.' instead of '/'.  I'd much
rather pass tree-item-url, which has the slashes in the first place.  

I appreciate the ZPT solution but the whole idea is to have a single method
at the top of the tree and manage the objects down in the leaves from there.
I have about 20 folders two levels down the tree and I'm sure the customer
will want subfolders below that eventually.  

Meanwhile, have a little patience with us newbies--you can't memorize the
manual in a day.  And the manual could certainly use some improvement, to
wit, if dtml is frowned upon, put ZPT first and clearly mention that it is
the preferred approach and should be learned first.  Even my Python guru
down the hall finds some parts of Zope less than transparent.  You shouldn't
have to read source code in the .py files to get things done.  

Karl

-----Original Message-----
From: Chris Withers [mailto:lists at simplistix.co.uk] 
Sent: Thursday, March 25, 2004 2:53 AM
To: Horak, Karl
Cc: 'zope at zope.org'
Subject: Re: [Zope] Programmatically deleting objects


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