Calling the del function from a DTML document/method
Hello. Is it possible to call the del function(this deletes single/multiple items from a list) from a DTML document/method. If so, what is the correct syntax for this? Thanks. - Asad
From: "Asad Habib" <ahabib@engin.umich.edu>
Hello. Is it possible to call the del function(this deletes single/multiple items from a list) from a DTML document/method. If so, what is the correct syntax for this? Thanks.
Call format to delete an object is: <dtml-call "manage_delObjects([oid])"> Note: manage_delObjects expects a list of object ids, so you have two options: (i) pass it a list variable (which contains a list of ids to be deleted) or (ii) put a single variable/object id into a list. The latter is shown above. HTH Jonathan
Hello. Thanks for your help but what I was referring to is the Python function 'del'. Just like 'append' can be called from a DTML method/document to add to a variable of type list (e.g. <dtml-call "myList.append()">), can 'del' be called in a similar way? - Asad
From: "Asad Habib" <ahabib@engin.umich.edu>
Hello. Thanks for your help but what I was referring to is the Python function 'del'. Just like 'append' can be called from a DTML method/document to add to a variable of type list (e.g. <dtml-call "myList.append()">), can 'del' be called in a similar way?
I think what you are looking for is: <dtml-call "myList.remove(avar)"> where 'avar' contains the item that you want removed from the list (myList). Jonathan
Hi, I just needed the same thing... I had difficulty finding the answer. Here's my solution, I hope its helpful. Deleting Zope Objects in DTML based on timestamp. I created this for housekeeping of a file repository,very similar the the File Library app in the Zope Examples. This dtml-method deletes items of type "File" that haven't been modified in 45 days. Notice the syntax in the line: <dtml-call expr="manage_delObjects([_['id'],])"> I Google'd it, apparently its handing manage_delObjects a list of one item, and that item is the item "id" from the current namespace. The trailing comma is for a list of one item. To test it, I commented the manage_delObjects line, and included the commented lines below, to test for the correct results. <dtml-with Files> <dtml-in expr="objectItems('File')" sort="bobobase_modification_time" reverse> <dtml-with sequence-item> <dtml-if expr="bobobase_modification_time()<=ZopeTime()-45"> <!-- DEL: <dtml-var absolute_url><br> --> <dtml-call expr="manage_delObjects([_['id'],])"> <dtml-else> <!-- KEEP: <dtml-var absolute_url><br> --> </dtml-if> </dtml-with> </dtml-in> </dtml-with> <dtml-call "RESPONSE.redirect('filelist_html')"> Good Luck, -Jonathan Cyr Asad Habib wrote:
Hello. Is it possible to call the del function(this deletes single/multiple items from a list) from a DTML document/method. If so, what is the correct syntax for this? Thanks.
- Asad
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Jonathan Cyr wrote:
<dtml-with Files> <dtml-in expr="objectItems('File')" sort="bobobase_modification_time" reverse> <dtml-with sequence-item> <dtml-if expr="bobobase_modification_time()<=ZopeTime()-45"> <!-- DEL: <dtml-var absolute_url><br> --> <dtml-call expr="manage_delObjects([_['id'],])"> <dtml-else> <!-- KEEP: <dtml-var absolute_url><br> --> </dtml-if> </dtml-with> </dtml-in> </dtml-with> <dtml-call "RESPONSE.redirect('filelist_html')">
For gods sake, do this in a python script! cutoff = DateTime()-45 for file in context.Files.objectValues('File'): if file.bobobase_modification_time()<=cutoff: context.Files.manage_delObjects([file.getId()]) return context.filelist_html() or, more compactly: cutoff = DateTime()-45 context.Files.manage_delObjects( [file.getId() for file in context.Files.objectValues('File') if file.bobobase_modification_time()<=cutoff ] ) return context.filelist_html() Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Thanks, Very happy to be outdone... use the Python Script... much more elegant in a python script. Sometimes it's very unclear how to access Zope's resources from Python Scripts. I own every Zope Book published, and wouldn't have grokked that solution. Thanks for contributing to this newbie item, -Jon
participants (4)
-
Asad Habib -
Chris Withers -
Jonathan Cyr -
Small Business Services