Back to index

plone3  3.1.7
typeinfo.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """TypeInformation browser views.
00014 
00015 $Id: typeinfo.py 73035 2007-03-07 16:41:03Z jens $
00016 """
00017 
00018 from xml.dom.minidom import parseString
00019 
00020 from zope.component import queryMultiAdapter
00021 from zope.component import queryUtility
00022 
00023 from Products.CMFCore.TypesTool import FactoryTypeInformation
00024 from Products.CMFCore.TypesTool import ScriptableTypeInformation
00025 from Products.GenericSetup.browser.utils import AddWithPresettingsViewBase
00026 from Products.GenericSetup.interfaces import IBody
00027 from Products.GenericSetup.interfaces import ISetupTool
00028 
00029 
00030 class FactoryTypeInformationAddView(AddWithPresettingsViewBase):
00031 
00032     """Add view for FactoryTypeInformation.
00033     """
00034 
00035     klass = FactoryTypeInformation
00036 
00037     description = u'A type information object defines a portal type.'
00038 
00039     def getProfileInfos(self):
00040         profiles = []
00041         stool = queryUtility(ISetupTool)
00042         if stool:
00043             for info in stool.listContextInfos():
00044                 obj_ids = []
00045                 context = stool._getImportContext(info['id'])
00046                 file_ids = context.listDirectory('types')
00047                 for file_id in file_ids or ():
00048                     if not file_id.endswith('.xml'):
00049                         continue
00050 
00051                     filename = 'types/%s' % file_id
00052                     body = context.readDataFile(filename)
00053                     if body is None:
00054                         continue
00055 
00056                     root = parseString(body).documentElement
00057                     meta_type = str(root.getAttribute('meta_type'))
00058                     if meta_type != self.klass.meta_type:
00059                         continue
00060 
00061                     obj_id = str(root.getAttribute('name'))
00062                     obj_ids.append(obj_id)
00063                 if not obj_ids:
00064                     continue
00065                 obj_ids.sort()
00066                 profiles.append({'id': info['id'],
00067                                  'title': info['title'],
00068                                  'obj_ids': tuple(obj_ids)})
00069         return tuple(profiles)
00070 
00071     def _initSettings(self, obj, profile_id, obj_path):
00072         stool = queryUtility(ISetupTool)
00073         if stool is None:
00074             return
00075 
00076         context = stool._getImportContext(profile_id)
00077         file_ids = context.listDirectory('types')
00078         for file_id in file_ids or ():
00079             if not file_id.endswith('.xml'):
00080                 continue
00081 
00082             filename = 'types/%s' % file_id
00083             body = context.readDataFile(filename)
00084             if body is None:
00085                 continue
00086 
00087             root = parseString(body).documentElement
00088             new_id = str(root.getAttribute('name'))
00089             if new_id != obj_path[0]:
00090                 continue
00091 
00092             meta_type = str(root.getAttribute('meta_type'))
00093             if meta_type != self.klass.meta_type:
00094                 continue
00095 
00096             importer = queryMultiAdapter((obj, context), IBody)
00097             if importer is None:
00098                 continue
00099 
00100             importer.body = body
00101             return
00102 
00103 
00104 class ScriptableTypeInformationAddView(FactoryTypeInformationAddView):
00105 
00106     """Add view for ScriptableTypeInformation.
00107     """
00108 
00109     klass = ScriptableTypeInformation