[Zope] dtml-in --> sequence

Casey Duncan cduncan@kaivo.com
Fri, 06 Apr 2001 08:56:22 -0600


After Dark wrote:
> 
> Hi, I`m trying to delete some objects(folders/files), but
> I`m having some problems with sequence-...
> 
> I`m trying to use manage_delObjects()... I made a list of
> sequence-item with a <dtml-in "Folder.objectValues()">, can
> I pass this list like an argument to manage_delObjects?
> Like <dtml-call "manage_delObjects(list)">
> 
> I think I a little confused with <sequence-..>, when I make
> a list like that (objectValues of a folder), do I have the
> object in <sequence-item>? If I make sequence-var-title, is
> it going to return the title? --> Because it`s giving error.
> Or I just have the id and I have to make
> _.getitem(sequence-item).title?
> 
> I tryed to compare the sequence-item variable and returned
> error too... : <dtml-if "sequence-item=='test'">
> 
> By.

You have run into a classic problem that has burned many a thread. The
name "sequence-item" is not a valid Python variable name, so it must be
accessed indirectly when in an expression using the syntax
_['sequence-item']. This is hopefully going to be fixed soon in a future
release.

So, to do your comparison you would need:

<dtml-if expr="_['sequence-item'] == 'test'">

As for manage_delObjects, it takes a sequences of strings as its
argument. These strings are the ids of the objects to delete.
objectValues returns objects, not strings. However, objectIds returns
the ids as a sequence of strings.

So, you could delete all instances of a particular type of object in a
folder like so:

<dtml-call expr="manage_delObjects(objectIds('meta type'))">

If you want to make an arbitrary list, you would probably do better
using a python script, as DTML is not well suited to logic, such as
sequence manipulation. Here's an example:

del_list = []
for ob in context.objectValues('meta type'):
    if ...insert your comparison here...:
        del_list.append(ob.id)
if del_list: context.manage_delObjects(del_list)

Calling this script in the context of the folder containing the objects,
would find the objects to delete and obliterate them.

hth,
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>