Back to index

plone3  3.1.7
actions.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: actions.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.ActionInformation import Action
00024 from Products.CMFCore.ActionInformation import ActionCategory
00025 from Products.GenericSetup.browser.utils import AddWithPresettingsViewBase
00026 from Products.GenericSetup.interfaces import INode
00027 from Products.GenericSetup.interfaces import ISetupTool
00028 
00029 
00030 class ActionAddView(AddWithPresettingsViewBase):
00031 
00032     """Add view for Action.
00033     """
00034 
00035     klass = Action
00036 
00037     description = u'An Action object represents a reference to an action.'
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                 body = context.readDataFile('actions.xml')
00047                 if body is None:
00048                     continue
00049                 root = parseString(body).documentElement
00050                 for node in root.childNodes:
00051                     if node.nodeName != 'object':
00052                         continue
00053                     obj_ids += self._extractChildren(node)
00054                 obj_ids.sort()
00055                 profiles.append({'id': info['id'],
00056                                  'title': info['title'],
00057                                  'obj_ids': tuple(obj_ids)})
00058         return tuple(profiles)
00059 
00060     def _extractChildren(self, node):
00061         action_paths = []
00062         category_id = node.getAttribute('name')
00063         for child in node.childNodes:
00064             if child.nodeName != 'object':
00065                 continue
00066             if child.getAttribute('meta_type') == self.klass.meta_type:
00067                 action_id = child.getAttribute('name')
00068                 action_paths.append(action_id)
00069             else:
00070                 action_paths += self._extractChildren(child)
00071         return [ ('%s/%s' % (category_id, path)) for path in action_paths ]
00072 
00073     def _initSettings(self, obj, profile_id, obj_path):
00074         stool = queryUtility(ISetupTool)
00075         if stool is None:
00076             return
00077 
00078         context = stool._getImportContext(profile_id)
00079         body = context.readDataFile('actions.xml')
00080         if body is None:
00081             return
00082 
00083         settings_node = None
00084         root = parseString(body).documentElement
00085         for node in root.childNodes:
00086             if node.nodeName != 'object':
00087                 continue
00088             for obj_id in obj_path:
00089                 for child in node.childNodes:
00090                     if child.nodeName != 'object':
00091                         continue
00092                     if child.getAttribute('name') != obj_id:
00093                         continue
00094                     if child.getAttribute('meta_type') == self.klass.meta_type:
00095                         settings_node = child
00096                     else:
00097                         node = child
00098                     break
00099 
00100         importer = queryMultiAdapter((obj, context), INode)
00101         if importer is None:
00102             return
00103 
00104         importer.node = settings_node
00105         return
00106 
00107 
00108 class ActionCategoryAddView(AddWithPresettingsViewBase):
00109 
00110     """Add view for ActionCategory.
00111     """
00112 
00113     klass = ActionCategory
00114 
00115     description = \
00116             u'An Action Category object represents a group of Action objects.'
00117 
00118     def getProfileInfos(self):
00119         return []
00120 
00121     def _initSettings(self, obj, profile_id, obj_path):
00122         pass