[Zope] programmatically renaming multiple objects

Jerome Alet alet@unice.fr
Mon, 23 Jul 2001 22:38:20 +0200


--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii

On Mon, Jul 23, 2001 at 07:29:04PM +0200, Dirk Schneider wrote:
> I am looking for a way to change the id's of multiple objects by a method. I
> have a DTML-Document that is filled with objects (paragraphs) by <dtml-in>.
> What I want to do is to be able to insert a new object by a web interface at
> any place in the list, not only at the end. When I want to insert the new
> object in the middle, I have to rename all objects that follow. Does someone
> know a way how to do it?

Use manage_renameObjects(), but beware because there's a bug in it which makes
it unable to rename successfully in some 'at-first-glance' conflictuous 
situations. This bug prevents you from doing batch renames like what
you want to do, forcing you to call 'manually' the less powerful
manage_renameObject() method (NB: the missing 's').

Anyway, an ugly patch is attached to this message, maybe for the third 
time, but it seems it was never applied, and the corresponding Collector 
entry was probably lost somewhere or not read at all :-((

bye,

Jerome Alet


--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="CopySupport.py.patch"

--- lib/python/OFS/CopySupport.py	Mon Apr 16 18:26:20 2001
+++ lib/python/OFS/CopySupport.py.new	Sun Jun 24 20:58:48 2001
@@ -281,9 +281,20 @@
         """Rename several sub-objects"""
         if len(ids) != len(new_ids):
             raise 'Bad Request','Please rename each listed object.'
+        conflicts = []    
         for i in range(len(ids)):
             if ids[i] != new_ids[i]:
+                if new_ids[i] not in ids :      # may a conflict occur ?
                 self.manage_renameObject(ids[i], new_ids[i], REQUEST)
+                else :        
+                        tempo = ".temporary_%i_" % i
+                        self.manage_renameObject(ids[i], tempo)
+                        conflicts.append((tempo, new_ids[i]))
+                        
+        # now we rename conflictuous objects                
+        for (old, new) in conflicts :               
+                self.manage_renameObject(old, new)
+                
         if REQUEST is not None:
             return self.manage_main(self, REQUEST, update_menu=1)
         return None

--zYM0uCDKw75PZbzx--