source: waeup_product/trunk/PatchCPSDefaultImportExport.py @ 264

Last change on this file since 264 was 263, checked in by lregebro, 18 years ago

Profiles that work.

  • Property svn:keywords set to Id
File size: 2.6 KB
RevLine 
[263]1from Products.CPSDocument.exportimport import importCPSObjects
2from Products.CMFCore.utils import getToolByName
3from zope.app import zapi
4from Products.GenericSetup.interfaces import INode
5import Products
6
7def _initObjects(self, node):
8    for child in node.childNodes:
9        if child.nodeName != 'object':
10            continue
11        if child.hasAttribute('deprecated'):
12            continue
13        parent = self.context
14
15        obj_id = str(child.getAttribute('name'))
16        if child.hasAttribute('remove'):
17            parent._delObject(obj_id)
18            continue
19
20        if obj_id not in parent.objectIds():
21            portal_type = str(child.getAttribute('portal_type'))
22            if portal_type:
23                wftool = getToolByName(parent, 'portal_workflow')
24                wftool.invokeFactoryFor(parent, portal_type, obj_id)
25            else:
26                meta_type = str(child.getAttribute('meta_type'))
27                __traceback_info__ = obj_id, meta_type
28                for mt_info in Products.meta_types:
29                    if mt_info['name'] == meta_type:
30                        parent._setObject(obj_id, mt_info['instance'](obj_id))
31                        break
32                else:
33                    raise ValueError("unknown meta_type '%s'" % meta_type)
34                       
35
36        if child.hasAttribute('insert-before'):
37            insert_before = child.getAttribute('insert-before')
38            if insert_before == '*':
39                parent.moveObjectsToTop(obj_id)
40            else:
41                try:
42                    position = parent.getObjectPosition(insert_before)
43                    if parent.getObjectPosition(obj_id) < position:
44                        position -= 1
45                    parent.moveObjectToPosition(obj_id, position)
46                except ValueError:
47                    pass
48        elif child.hasAttribute('insert-after'):
49            insert_after = child.getAttribute('insert-after')
50            if insert_after == '*':
51                parent.moveObjectsToBottom(obj_id)
52            else:
53                try:
54                    position = parent.getObjectPosition(insert_after)
55                    if parent.getObjectPosition(obj_id) < position:
56                        position -= 1
57                    parent.moveObjectToPosition(obj_id, position+1)
58                except ValueError:
59                    pass
60
61        obj = getattr(self.context, obj_id)
62        importer = zapi.queryMultiAdapter((obj, self.environ), INode)
63        if importer:
64            importer.node = child
65
66from Products.CPSDefault.exportimport import RootXMLAdapter
67RootXMLAdapter._initObjects = _initObjects
68
Note: See TracBrowser for help on using the repository browser.