vendor/CMF/1.6.3/CMFCore

view browser/typeinfo.py @ 2:4c712d7bd1d7

Added tag 1.6.3 for changeset 1babb9d61518
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Fri, 09 Sep 2011 12:44:00 +0200
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """TypeInformation browser views.
15 $Id$
16 """
18 from xml.dom.minidom import parseString
20 from zope.component import queryMultiAdapter
22 from Products.CMFCore.TypesTool import FactoryTypeInformation
23 from Products.CMFCore.TypesTool import ScriptableTypeInformation
24 from Products.CMFCore.utils import getToolByName
25 from Products.GenericSetup.browser.utils import AddWithPresettingsViewBase
26 from Products.GenericSetup.interfaces import IBody
29 class FactoryTypeInformationAddView(AddWithPresettingsViewBase):
31 """Add view for FactoryTypeInformation.
32 """
34 klass = FactoryTypeInformation
36 description = u'A type information object defines a portal type.'
38 def getProfileInfos(self):
39 profiles = []
40 stool = getToolByName(self, 'portal_setup', None)
41 if stool:
42 for info in stool.listContextInfos():
43 obj_ids = []
44 context = stool._getImportContext(info['id'])
45 file_ids = context.listDirectory('types')
46 for file_id in file_ids or ():
47 if not file_id.endswith('.xml'):
48 continue
50 filename = 'types/%s' % file_id
51 body = context.readDataFile(filename)
52 if body is None:
53 continue
54 root = parseString(body).documentElement
55 obj_id = str(root.getAttribute('name'))
56 if not obj_id:
57 # BBB: for CMF 1.5 profiles
58 obj_id = str(root.getAttribute('id'))
59 # BBB: for CMF 1.5 profiles
60 meta_type = str(root.getAttribute('kind'))
61 if not meta_type:
62 meta_type = str(root.getAttribute('meta_type'))
63 if meta_type != self.klass.meta_type:
64 continue
65 obj_ids.append(obj_id)
66 if not obj_ids:
67 continue
68 obj_ids.sort()
69 profiles.append({'id': info['id'],
70 'title': info['title'],
71 'obj_ids': tuple(obj_ids)})
72 return tuple(profiles)
74 def _initSettings(self, obj, profile_id, obj_path):
75 stool = getToolByName(self, 'portal_setup', None)
76 if stool is None:
77 return
79 context = stool._getImportContext(profile_id)
80 file_ids = context.listDirectory('types')
81 for file_id in file_ids or ():
82 if not file_id.endswith('.xml'):
83 continue
85 filename = 'types/%s' % file_id
86 body = context.readDataFile(filename)
87 if body is None:
88 continue
90 root = parseString(body).documentElement
91 new_id = str(root.getAttribute('name'))
92 if not new_id:
93 # BBB: for CMF 1.5 profiles
94 new_id = str(root.getAttribute('id'))
95 if new_id != obj_path[0]:
96 continue
98 # BBB: for CMF 1.5 profiles
99 meta_type = str(root.getAttribute('kind'))
100 if not meta_type:
101 meta_type = str(root.getAttribute('meta_type'))
102 if meta_type != self.klass.meta_type:
103 continue
105 importer = queryMultiAdapter((obj, context), IBody)
106 if importer is None:
107 continue
109 importer.body = body
110 return
113 class ScriptableTypeInformationAddView(FactoryTypeInformationAddView):
115 """Add view for ScriptableTypeInformation.
116 """
118 klass = ScriptableTypeInformation