from Products.CPSDocument.exportimport import importCPSObjects from Products.CMFCore.utils import getToolByName from zope.app import zapi from Products.GenericSetup.interfaces import INode import Products # Patch to allow the roots importer to create CMF objects. # Only for CPS 3.4.1. In 3.4.2 and later this should be fixed. def _initObjects(self, node): for child in node.childNodes: if child.nodeName != 'object': continue if child.hasAttribute('deprecated'): continue parent = self.context obj_id = str(child.getAttribute('name')) if child.hasAttribute('remove'): parent._delObject(obj_id) continue if obj_id not in parent.objectIds(): portal_type = str(child.getAttribute('portal_type')) if portal_type: wftool = getToolByName(parent, 'portal_workflow') wftool.invokeFactoryFor(parent, portal_type, obj_id) else: meta_type = str(child.getAttribute('meta_type')) __traceback_info__ = obj_id, meta_type for mt_info in Products.meta_types: if mt_info['name'] == meta_type: parent._setObject(obj_id, mt_info['instance'](obj_id)) break else: raise ValueError("unknown meta_type '%s'" % meta_type) if child.hasAttribute('insert-before'): insert_before = child.getAttribute('insert-before') if insert_before == '*': parent.moveObjectsToTop(obj_id) else: try: position = parent.getObjectPosition(insert_before) if parent.getObjectPosition(obj_id) < position: position -= 1 parent.moveObjectToPosition(obj_id, position) except ValueError: pass elif child.hasAttribute('insert-after'): insert_after = child.getAttribute('insert-after') if insert_after == '*': parent.moveObjectsToBottom(obj_id) else: try: position = parent.getObjectPosition(insert_after) if parent.getObjectPosition(obj_id) < position: position -= 1 parent.moveObjectToPosition(obj_id, position+1) except ValueError: pass obj = getattr(self.context, obj_id) if child.hasAttribute('Title'): print "set title",obj_id obj.title = child.getAttribute('Title') importer = zapi.queryMultiAdapter((obj, self.environ), INode) if importer: importer.node = child from Products.CPSDefault.exportimport import RootXMLAdapter RootXMLAdapter._initObjects = _initObjects