1 | from Products.CPSDocument.exportimport import importCPSObjects |
---|
2 | from Products.CMFCore.utils import getToolByName |
---|
3 | from zope.app import zapi |
---|
4 | from Products.GenericSetup.interfaces import INode |
---|
5 | import Products |
---|
6 | |
---|
7 | # Patch to allow the roots importer to create CMF objects. |
---|
8 | # Only for CPS 3.4.1. In 3.4.2 and later this should be fixed. |
---|
9 | |
---|
10 | def _initObjects(self, node): |
---|
11 | for child in node.childNodes: |
---|
12 | if child.nodeName != 'object': |
---|
13 | continue |
---|
14 | if child.hasAttribute('deprecated'): |
---|
15 | continue |
---|
16 | parent = self.context |
---|
17 | |
---|
18 | obj_id = str(child.getAttribute('name')) |
---|
19 | if child.hasAttribute('remove'): |
---|
20 | parent._delObject(obj_id) |
---|
21 | continue |
---|
22 | |
---|
23 | if obj_id not in parent.objectIds(): |
---|
24 | portal_type = str(child.getAttribute('portal_type')) |
---|
25 | if portal_type: |
---|
26 | wftool = getToolByName(parent, 'portal_workflow') |
---|
27 | wftool.invokeFactoryFor(parent, portal_type, obj_id) |
---|
28 | else: |
---|
29 | meta_type = str(child.getAttribute('meta_type')) |
---|
30 | __traceback_info__ = obj_id, meta_type |
---|
31 | for mt_info in Products.meta_types: |
---|
32 | if mt_info['name'] == meta_type: |
---|
33 | parent._setObject(obj_id, mt_info['instance'](obj_id)) |
---|
34 | break |
---|
35 | else: |
---|
36 | raise ValueError("unknown meta_type '%s'" % meta_type) |
---|
37 | |
---|
38 | |
---|
39 | if child.hasAttribute('insert-before'): |
---|
40 | insert_before = child.getAttribute('insert-before') |
---|
41 | if insert_before == '*': |
---|
42 | parent.moveObjectsToTop(obj_id) |
---|
43 | else: |
---|
44 | try: |
---|
45 | position = parent.getObjectPosition(insert_before) |
---|
46 | if parent.getObjectPosition(obj_id) < position: |
---|
47 | position -= 1 |
---|
48 | parent.moveObjectToPosition(obj_id, position) |
---|
49 | except ValueError: |
---|
50 | pass |
---|
51 | elif child.hasAttribute('insert-after'): |
---|
52 | insert_after = child.getAttribute('insert-after') |
---|
53 | if insert_after == '*': |
---|
54 | parent.moveObjectsToBottom(obj_id) |
---|
55 | else: |
---|
56 | try: |
---|
57 | position = parent.getObjectPosition(insert_after) |
---|
58 | if parent.getObjectPosition(obj_id) < position: |
---|
59 | position -= 1 |
---|
60 | parent.moveObjectToPosition(obj_id, position+1) |
---|
61 | except ValueError: |
---|
62 | pass |
---|
63 | |
---|
64 | obj = getattr(self.context, obj_id) |
---|
65 | if child.hasAttribute('Title'): |
---|
66 | print "set title",obj_id |
---|
67 | obj.title = child.getAttribute('Title') |
---|
68 | |
---|
69 | importer = zapi.queryMultiAdapter((obj, self.environ), INode) |
---|
70 | if importer: |
---|
71 | importer.node = child |
---|
72 | |
---|
73 | from Products.CPSDefault.exportimport import RootXMLAdapter |
---|
74 | RootXMLAdapter._initObjects = _initObjects |
---|
75 | |
---|