[CMF-checkins] SVN: CMF/trunk/GenericSetup/utils.py - if objects don't provide IOrderedContainer, sort sub-objects by name

Yvo Schubbe y.2005- at wcm-solutions.de
Thu Nov 24 06:14:18 EST 2005


Log message for revision 40351:
  - if objects don't provide IOrderedContainer, sort sub-objects by name
  - create a small 'object' node for sub-objects without node adapter

Changed:
  U   CMF/trunk/GenericSetup/utils.py

-=-
Modified: CMF/trunk/GenericSetup/utils.py
===================================================================
--- CMF/trunk/GenericSetup/utils.py	2005-11-24 02:54:51 UTC (rev 40350)
+++ CMF/trunk/GenericSetup/utils.py	2005-11-24 11:14:17 UTC (rev 40351)
@@ -29,6 +29,11 @@
 from Acquisition import Implicit
 from Globals import InitializeClass
 from Globals import package_home
+try:
+    from OFS.interfaces import IOrderedContainer
+except:
+    #BBB: for Zope 2.8
+    from Products.Five.bbb.OFS_interfaces import IOrderedContainer
 from TAL.TALDefs import attrEscape
 from zope.app import zapi
 from zope.interface import implements
@@ -501,11 +506,18 @@
 
     def _extractObjects(self):
         fragment = self._doc.createDocumentFragment()
-        for obj in self.context.objectValues():
+        objects = self.context.objectValues()
+        if not IOrderedContainer.providedBy(self.context):
+            objects.sort(lambda x,y: cmp(x.getId(), y.getId()))
+        for obj in objects:
             exporter = INodeExporter(obj, None)
             if exporter is None:
-                continue
-            fragment.appendChild(exporter.exportNode(self._doc))
+                node = self._doc.createElement('object')
+                node.setAttribute('name', obj.getId())
+                node.setAttribute('meta_type', obj.meta_type)
+            else:
+                node = exporter.exportNode(self._doc)
+            fragment.appendChild(node)
         return fragment
 
     def _purgeObjects(self):
@@ -528,7 +540,7 @@
                         parent._setObject(obj_id, mt_info['instance'](obj_id))
                         break
                 else:
-                    raise ValueError('unknown meta_type \'%s\'' % obj_id)
+                    raise ValueError('unknown meta_type \'%s\'' % meta_type)
 
             if child.hasAttribute('insert-before'):
                 insert_before = child.getAttribute('insert-before')



More information about the CMF-checkins mailing list