vendor/CMF/1.6.3/CMFCore

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