Commit 8e397c79 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: BusinessTemplate.

parent 7252a5f5
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
import six import six
from six import string_types as basestring from six import string_types as basestring
from Products.ERP5Type.Utils import ensure_list, bytes2str
import fnmatch, gc, glob, imp, os, re, shutil, sys, time, tarfile import fnmatch, gc, glob, imp, os, re, shutil, sys, time, tarfile
from collections import defaultdict from collections import defaultdict
from Shared.DC.ZRDB import Aqueduct from Shared.DC.ZRDB import Aqueduct
...@@ -130,33 +131,38 @@ SEPARATELY_EXPORTED_PROPERTY_DICT = { ...@@ -130,33 +131,38 @@ SEPARATELY_EXPORTED_PROPERTY_DICT = {
# separate file, with extension specified by 'extension'. # separate file, with extension specified by 'extension'.
# 'extension' must be None for auto-detection. # 'extension' must be None for auto-detection.
# #
# class_name: (extension, unicode_data, property_name), # XXX-py3: `text` was added but what we should do is check the PropertySheet
"Document Component": ("py", 0, "text_content"), # ('string' (str) /'data' (bytes)) but for now, only work on
"DTMLDocument": (None, 0, "raw"), # bootstrap...
"DTMLMethod": (None, 0, "raw"), #
"Extension Component": ("py", 0, "text_content"), # class_name: (extension, unicode_data, property_name, text),
"File": (None, 0, "data"), "Document Component": ("py", 0, "text_content", True ),
"Image": (None, 0, "data"), "DTMLDocument": (None, 0, "raw", True ),
"Interface Component": ("py", 0, "text_content"), "DTMLMethod": (None, 0, "raw", True ),
"OOoTemplate": ("oot", 1, "_text"), "Extension Component": ("py", 0, "text_content", True ),
"Mixin Component": ("py", 0, "text_content"), # OFS.File raises ValueError("Must be bytes")
"Module Component": ("py", 0, "text_content"), "File": (None, 0, "data", False),
"PDF": ("pdf", 0, "data"), "Image": (None, 0, "data", False),
"PyData Script": ("py", 0, "_body"), "Interface Component": ("py", 0, "text_content", True ),
"Python Script": ("py", 0, "_body"), "OOoTemplate": ("oot", 1, "_text", True ),
"Workflow Script": ("py", 0, "_body"), "Mixin Component": ("py", 0, "text_content", True ),
"PythonScript": ("py", 0, "_body"), "Module Component": ("py", 0, "text_content", True ),
"Spreadsheet": (None, 0, "data"), "PDF": ("pdf", 0, "data", False),
"SQL": ("sql", 0, "src"), "PyData Script": ("py", 0, "_body", True ),
"SQL Method": ("sql", 0, "src"), "Python Script": ("py", 0, "_body", True ),
"Test Component": ("py", 0, "text_content"), "Workflow Script": ("py", 0, "_body", True ),
"Test Page": (None, 0, "text_content"), "PythonScript": ("py", 0, "_body", True ),
"Tool Component": ("py", 0, "text_content"), "Spreadsheet": (None, 0, "data", False),
"Web Illustration": ("svg", 0, "text_content"), "SQL": ("sql", 0, "src", True ),
"Web Page": (None, 0, "text_content"), "SQL Method": ("sql", 0, "src", True ),
"Web Script": (None, 0, "text_content"), "Test Component": ("py", 0, "text_content", True ),
"Web Style": (None, 0, "text_content"), "Test Page": (None, 0, "text_content", True ),
"ZopePageTemplate": ("zpt", 1, "_text"), "Tool Component": ("py", 0, "text_content", True ),
"Web Illustration": ("svg", 0, "text_content", True ),
"Web Page": (None, 0, "text_content", True ),
"Web Script": (None, 0, "text_content", True ),
"Web Style": (None, 0, "text_content", True ),
"ZopePageTemplate": ("zpt", 1, "_text", True ),
} }
def _getCatalog(acquisition_context): def _getCatalog(acquisition_context):
...@@ -813,7 +819,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -813,7 +819,7 @@ class ObjectTemplateItem(BaseTemplateItem):
bta.addObject(obj, name=key, ext='.py') bta.addObject(obj, name=key, ext='.py')
else: else:
try: try:
extension, unicode_data, record_id = \ extension, unicode_data, record_id, _ = \
SEPARATELY_EXPORTED_PROPERTY_DICT[obj.__class__.__name__] SEPARATELY_EXPORTED_PROPERTY_DICT[obj.__class__.__name__]
except KeyError: except KeyError:
pass pass
...@@ -867,10 +873,13 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -867,10 +873,13 @@ class ObjectTemplateItem(BaseTemplateItem):
bta.addObject(xml_data, key + '.catalog_keys', path=path) bta.addObject(xml_data, key + '.catalog_keys', path=path)
def _restoreSeparatelyExportedProperty(self, obj, data): def _restoreSeparatelyExportedProperty(self, obj, data):
unicode_data, property_name = SEPARATELY_EXPORTED_PROPERTY_DICT[ class_name = obj.__class__.__name__
obj.__class__.__name__][1:] unicode_data, property_name, is_text = SEPARATELY_EXPORTED_PROPERTY_DICT[
class_name][1:]
if unicode_data: if unicode_data:
data = data.decode(obj.output_encoding) data = data.decode(obj.output_encoding)
elif is_text:
data = data.decode('utf-8')
try: try:
setattr(obj, property_name, data) setattr(obj, property_name, data)
except BrokenModified: except BrokenModified:
...@@ -1028,7 +1037,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1028,7 +1037,8 @@ class ObjectTemplateItem(BaseTemplateItem):
F.binary=1 F.binary=1
F.file=outfile F.file=outfile
p=xml.parsers.expat.ParserCreate('utf-8') p=xml.parsers.expat.ParserCreate('utf-8')
p.returns_unicode = False if six.PY2:
p.returns_unicode = False
p.CharacterDataHandler=F.handle_data p.CharacterDataHandler=F.handle_data
p.StartElementHandler=F.unknown_starttag p.StartElementHandler=F.unknown_starttag
p.EndElementHandler=F.unknown_endtag p.EndElementHandler=F.unknown_endtag
...@@ -1184,7 +1194,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1184,7 +1194,7 @@ class ObjectTemplateItem(BaseTemplateItem):
def _getObjectKeyList(self): def _getObjectKeyList(self):
# sort to add objects before their subobjects # sort to add objects before their subobjects
keys = self._objects.keys() keys = ensure_list(self._objects.keys())
keys.sort() keys.sort()
return keys return keys
...@@ -1546,7 +1556,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1546,7 +1556,7 @@ class ObjectTemplateItem(BaseTemplateItem):
if widget_path in update_dict and update_dict[widget_path] in ('remove', 'save_and_remove'): if widget_path in update_dict and update_dict[widget_path] in ('remove', 'save_and_remove'):
continue continue
widget_in_form = 0 widget_in_form = 0
for group_value_list in new_groups_dict.values(): for group_value_list in new_groups_dict.itervalues():
if widget_id in group_value_list: if widget_id in group_value_list:
widget_in_form = 1 widget_in_form = 1
break break
...@@ -1617,7 +1627,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1617,7 +1627,7 @@ class ObjectTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive
for relative_url in object_keys: for relative_url in object_keys:
container_path = relative_url.split('/')[0:-1] container_path = relative_url.split('/')[0:-1]
object_id = relative_url.split('/')[-1] object_id = relative_url.split('/')[-1]
...@@ -1650,7 +1660,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1650,7 +1660,7 @@ class PathTemplateItem(ObjectTemplateItem):
""" """
def __init__(self, id_list, tool_id=None, **kw): def __init__(self, id_list, tool_id=None, **kw):
BaseTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw) BaseTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
id_list = self._archive.keys() id_list = ensure_list(self._archive.keys())
self._archive.clear() self._archive.clear()
self._path_archive = PersistentMapping() self._path_archive = PersistentMapping()
for id in id_list: for id in id_list:
...@@ -1664,7 +1674,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1664,7 +1674,7 @@ class PathTemplateItem(ObjectTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._path_archive.keys() object_keys = ensure_list(self._path_archive.keys())
object_keys.sort() object_keys.sort()
object_keys.reverse() object_keys.reverse()
p = context.getPortalObject() p = context.getPortalObject()
...@@ -1719,7 +1729,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1719,7 +1729,7 @@ class PathTemplateItem(ObjectTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
keys = self._path_archive.keys() keys = ensure_list(self._path_archive.keys())
keys.sort() keys.sort()
for path in keys: for path in keys:
include_subobjects = 0 include_subobjects = 0
...@@ -1823,7 +1833,7 @@ class ToolTemplateItem(PathTemplateItem): ...@@ -1823,7 +1833,7 @@ class ToolTemplateItem(PathTemplateItem):
object_dict = super(ToolTemplateItem, self).preinstall(context, installed_item, **kw) object_dict = super(ToolTemplateItem, self).preinstall(context, installed_item, **kw)
portal_base = aq_base(context.getPortalObject()) portal_base = aq_base(context.getPortalObject())
for path, (action, type_name) in object_dict.items(): for path, (action, type_name) in ensure_list(object_dict.items()):
obj = getattr(portal_base, path, None) obj = getattr(portal_base, path, None)
if obj is not None and path in self._legacy_tool_id_list: if obj is not None and path in self._legacy_tool_id_list:
if action == 'New': if action == 'New':
...@@ -1859,7 +1869,7 @@ class ToolTemplateItem(PathTemplateItem): ...@@ -1859,7 +1869,7 @@ class ToolTemplateItem(PathTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._path_archive.keys() object_keys = self._path_archive
for tool_id in object_keys: for tool_id in object_keys:
types_tool.type_provider_list = tuple([ \ types_tool.type_provider_list = tuple([ \
x for x in types_tool.type_provider_list \ x for x in types_tool.type_provider_list \
...@@ -1871,8 +1881,7 @@ class ToolTemplateItem(PathTemplateItem): ...@@ -1871,8 +1881,7 @@ class ToolTemplateItem(PathTemplateItem):
portal = context.getPortalObject() portal = context.getPortalObject()
types_tool = portal.portal_types types_tool = portal.portal_types
remove_dict = kw.get('remove_object_dict', {}) remove_dict = kw.get('remove_object_dict', {})
keys = self._objects.keys() for tool_id in self._objects:
for tool_id in keys:
if tool_id in remove_dict: if tool_id in remove_dict:
action = remove_dict[tool_id] action = remove_dict[tool_id]
if 'remove' in action: if 'remove' in action:
...@@ -1908,7 +1917,7 @@ class PreferenceTemplateItem(PathTemplateItem): ...@@ -1908,7 +1917,7 @@ class PreferenceTemplateItem(PathTemplateItem):
""" """
PathTemplateItem.install(self, context, trashbin, **kw) PathTemplateItem.install(self, context, trashbin, **kw)
portal = context.getPortalObject() portal = context.getPortalObject()
for object_path in self._objects.keys(): for object_path in self._objects:
pref = portal.unrestrictedTraverse(object_path) pref = portal.unrestrictedTraverse(object_path)
# XXX getPreferenceState is a bad name # XXX getPreferenceState is a bad name
if pref.getPreferenceState() == 'disabled': if pref.getPreferenceState() == 'disabled':
...@@ -1945,7 +1954,7 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -1945,7 +1954,7 @@ class CategoryTemplateItem(ObjectTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
for relative_url in self._archive.keys(): for relative_url in self._archive:
try: try:
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context) obj = obj._getCopy(context)
...@@ -1983,7 +1992,7 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -1983,7 +1992,7 @@ class CategoryTemplateItem(ObjectTemplateItem):
# as PathTemplateItem.install # as PathTemplateItem.install
kw['object_to_update'] = { kw['object_to_update'] = {
path: action path: action
for (path, action) in kw['object_to_update'].items() for (path, action) in kw['object_to_update'].iteritems()
if path.split('/')[:-1] == ['portal_categories'] or path in self._objects if path.split('/')[:-1] == ['portal_categories'] or path in self._objects
} }
return super(CategoryTemplateItem, self).install(context, trashbin, **kw) return super(CategoryTemplateItem, self).install(context, trashbin, **kw)
...@@ -1996,7 +2005,7 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -1996,7 +2005,7 @@ class SkinTemplateItem(ObjectTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
ObjectTemplateItem.build(self, context, **kw) ObjectTemplateItem.build(self, context, **kw)
for relative_url in self._objects.keys(): for relative_url in self._objects:
obj = self._objects[relative_url] obj = self._objects[relative_url]
if (getattr(obj, 'meta_type', None) == 'Folder') and \ if (getattr(obj, 'meta_type', None) == 'Folder') and \
(obj.getProperty('business_template_registered_skin_selections', None) \ (obj.getProperty('business_template_registered_skin_selections', None) \
...@@ -2009,10 +2018,10 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -2009,10 +2018,10 @@ class SkinTemplateItem(ObjectTemplateItem):
# We must install/update an ERP5 Form if one of its widget is modified. # We must install/update an ERP5 Form if one of its widget is modified.
# This allow to keep the widget order and the form layout after an update # This allow to keep the widget order and the form layout after an update
# from a BT to another one. # from a BT to another one.
for (bt_obj_path, bt_obj) in self._objects.items(): for (bt_obj_path, bt_obj) in self._objects.iteritems():
if getattr(bt_obj, 'meta_type', None) == 'ERP5 Form': if getattr(bt_obj, 'meta_type', None) == 'ERP5 Form':
# search sub-objects of ERP5 Forms that are marked as "modified" # search sub-objects of ERP5 Forms that are marked as "modified"
for upd_obj_path in modified_object_list.keys(): for upd_obj_path in ensure_list(modified_object_list.keys()):
if upd_obj_path.startswith(bt_obj_path): if upd_obj_path.startswith(bt_obj_path):
# a child of the ERP5 Form must be updated, so the form too # a child of the ERP5 Form must be updated, so the form too
if bt_obj_path not in modified_object_list: if bt_obj_path not in modified_object_list:
...@@ -2025,7 +2034,7 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -2025,7 +2034,7 @@ class SkinTemplateItem(ObjectTemplateItem):
force = kw.get('force') force = kw.get('force')
p = context.getPortalObject() p = context.getPortalObject()
skin_tool = p.portal_skins skin_tool = p.portal_skins
for relative_url in self._objects.keys(): for relative_url in self._objects:
# Do not register skin which were explicitely ask not to be installed # Do not register skin which were explicitely ask not to be installed
if not force and update_dict.get(relative_url) == 'nothing': if not force and update_dict.get(relative_url) == 'nothing':
continue continue
...@@ -2049,7 +2058,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem): ...@@ -2049,7 +2058,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
portal = context.getPortalObject() portal = context.getPortalObject()
skin_tool = getToolByName(portal, 'portal_skins') skin_tool = getToolByName(portal, 'portal_skins')
for key in self._archive.keys(): for key in self._archive:
skin_folder_id, skin_selection_id = key.split(' | ') skin_folder_id, skin_selection_id = key.split(' | ')
skin_folder = skin_tool[skin_folder_id] skin_folder = skin_tool[skin_folder_id]
...@@ -2068,7 +2077,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem): ...@@ -2068,7 +2077,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
# Function to generate XML Code Manually # Function to generate XML Code Manually
def generateXml(self, path=None): def generateXml(self, path=None):
xml_data = '<registered_skin_selection>' xml_data = '<registered_skin_selection>'
keys = self._objects.keys() keys = ensure_list(self._objects.keys())
keys.sort() keys.sort()
for key in keys: for key in keys:
skin_selection_list = self._objects[key] skin_selection_list = self._objects[key]
...@@ -2094,7 +2103,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem): ...@@ -2094,7 +2103,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
portal = context.getPortalObject() portal = context.getPortalObject()
skin_tool = portal.portal_skins skin_tool = portal.portal_skins
for skin_folder_id in self._objects.keys(): for skin_folder_id in self._objects:
if skin_folder_id in update_dict or force: if skin_folder_id in update_dict or force:
if not force: if not force:
...@@ -2172,8 +2181,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem): ...@@ -2172,8 +2181,7 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
else: # new object else: # new object
modified_object_list[path] = 'New', self.__class__.__name__[:-12] modified_object_list[path] = 'New', self.__class__.__name__[:-12]
# get removed object # get removed object
old_keys = installed_item._objects.keys() for path in installed_item._objects:
for path in old_keys:
if path not in self._objects: if path not in self._objects:
modified_object_list[path] = 'Removed', self.__class__.__name__[:-12] modified_object_list[path] = 'Removed', self.__class__.__name__[:-12]
return modified_object_list return modified_object_list
...@@ -2404,7 +2412,7 @@ class WorkflowTemplateItem(ObjectTemplateItem): ...@@ -2404,7 +2412,7 @@ class WorkflowTemplateItem(ObjectTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive
removed_workflow_id_list = {x.split('/', 1)[1] for x in object_keys} removed_workflow_id_list = {x.split('/', 1)[1] for x in object_keys}
for portal_type in context.getPortalObject().portal_types.listTypeInfo(): for portal_type in context.getPortalObject().portal_types.listTypeInfo():
...@@ -2422,7 +2430,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -2422,7 +2430,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
for relative_url in self._archive.keys(): for relative_url in self._archive:
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
# normalize relative_url, not all type informations are stored in # normalize relative_url, not all type informations are stored in
# "portal_types" # "portal_types"
...@@ -2430,7 +2438,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -2430,7 +2438,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
obj = obj._getCopy(context) obj = obj._getCopy(context)
obj._p_activate() obj._p_activate()
for attr in obj.__dict__.keys(): for attr in ensure_list(obj.__dict__.keys()):
if attr == '_property_domain_dict': if attr == '_property_domain_dict':
continue continue
if attr[0] == '_' or attr in ('allowed_content_types', if attr[0] == '_' or attr in ('allowed_content_types',
...@@ -2447,7 +2455,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -2447,7 +2455,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
def _getObjectKeyList(self): def _getObjectKeyList(self):
# Sort portal types to install according to their dependencies # Sort portal types to install according to their dependencies
object_key_list = self._objects.keys() object_key_list = ensure_list(self._objects.keys())
path_dict = dict(x.split('/')[1:] + [x] for x in object_key_list) path_dict = dict(x.split('/')[1:] + [x] for x in object_key_list)
cache = {} cache = {}
def solveDependency(path): def solveDependency(path):
...@@ -2520,7 +2528,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -2520,7 +2528,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
# if - chain is removed from the exisiting one # if - chain is removed from the exisiting one
# if = chain replaced the existing one # if = chain replaced the existing one
types_tool = self.getPortalObject().portal_types types_tool = self.getPortalObject().portal_types
for key in self._archive.keys(): for key in self._archive:
wflist = key.split(' | ') wflist = key.split(' | ')
if len(wflist) == 2: if len(wflist) == 2:
portal_type = wflist[0] portal_type = wflist[0]
...@@ -2549,7 +2557,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -2549,7 +2557,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
# Function to generate XML Code Manually # Function to generate XML Code Manually
def generateXml(self, path=None): def generateXml(self, path=None):
xml_data = '<workflow_chain>' xml_data = '<workflow_chain>'
key_list = self._objects.keys() key_list = ensure_list(self._objects.keys())
key_list.sort() key_list.sort()
for key in key_list: for key in key_list:
workflow_list = self._objects[key] workflow_list = self._objects[key]
...@@ -2665,7 +2673,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem): ...@@ -2665,7 +2673,7 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
object_key_list = [object_path] object_key_list = [object_path]
else: else:
object_key_list = self._objects.keys() object_key_list = self._objects
for object_key in object_key_list: for object_key in object_key_list:
path_splitted = object_key.split('/', 1) path_splitted = object_key.split('/', 1)
if len(path_splitted) < 2: if len(path_splitted) < 2:
...@@ -2742,7 +2750,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): ...@@ -2742,7 +2750,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
types_tool = getToolByName(self.getPortalObject(), 'portal_types') types_tool = getToolByName(self.getPortalObject(), 'portal_types')
for key in self._archive.keys(): for key in self._archive:
try: try:
portal_type, allowed_type = key.split(' | ') portal_type, allowed_type = key.split(' | ')
except ValueError: except ValueError:
...@@ -2766,7 +2774,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): ...@@ -2766,7 +2774,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
# Function to generate XML Code Manually # Function to generate XML Code Manually
def generateXml(self, path=None): def generateXml(self, path=None):
xml_data = '<%s>' %(self.xml_tag,) xml_data = '<%s>' %(self.xml_tag,)
key_list = self._objects.keys() key_list = ensure_list(self._objects.keys())
key_list.sort() key_list.sort()
for key in key_list: for key in key_list:
id_value = key.replace('%s/' % self.class_property, '') id_value = key.replace('%s/' % self.class_property, '')
...@@ -2876,7 +2884,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem): ...@@ -2876,7 +2884,7 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
object_key_list = [object_path] object_key_list = [object_path]
else: else:
object_key_list = self._objects.keys() object_key_list = self._objects
for key in object_key_list: for key in object_key_list:
portal_id = key.split('/')[-1] portal_id = key.split('/')[-1]
type_information = types_tool.getTypeInfo(portal_id) type_information = types_tool.getTypeInfo(portal_id)
...@@ -2987,7 +2995,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -2987,7 +2995,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
if not hasattr(self, '_method_properties'): if not hasattr(self, '_method_properties'):
self._method_properties = PersistentMapping() self._method_properties = PersistentMapping()
for obj in self._objects.values(): for obj in self._objects.itervalues():
method_id = obj.id method_id = obj.id
# Check if the method is sub-object of Catalog # Check if the method is sub-object of Catalog
if method_id in catalog.objectIds(): if method_id in catalog.objectIds():
...@@ -3052,7 +3060,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -3052,7 +3060,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
portal = self.getPortalObject() portal = self.getPortalObject()
# Will be modifying dict, so better to use .items() # Will be modifying dict, so better to use .items()
# XXX: In python3 it should be .copy.items(). # XXX: In python3 it should be .copy.items().
for path, obj in self._objects.items(): for path, obj in ensure_list(self._objects.items()):
method = self.unrestrictedResolveValue(portal, path) method = self.unrestrictedResolveValue(portal, path)
method_id = path.split('/')[-1] method_id = path.split('/')[-1]
if method.meta_type == 'Z SQL Method': if method.meta_type == 'Z SQL Method':
...@@ -3063,7 +3071,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -3063,7 +3071,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
self._objects[path] = new_obj self._objects[path] = new_obj
if force: # get all objects if force: # get all objects
values = self._objects.values() values = ensure_list(self._objects.values())
else: # get only selected object else: # get only selected object
for key, value in six.iteritems(self._objects): for key, value in six.iteritems(self._objects):
if key in update_dict or force: if key in update_dict or force:
...@@ -3078,7 +3086,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -3078,7 +3086,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
# Restore catalog properties for methods # Restore catalog properties for methods
if hasattr(self, '_method_properties'): if hasattr(self, '_method_properties'):
for key in self._method_properties.get(method_id, {}).keys(): for key in self._method_properties.get(method_id, {}):
old_value = getattr(catalog, key, None) old_value = getattr(catalog, key, None)
if isinstance(old_value, str): if isinstance(old_value, str):
setattr(catalog, key, method_id) setattr(catalog, key, method_id)
...@@ -3156,7 +3164,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -3156,7 +3164,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
object_path = kw.get('object_path', None) object_path = kw.get('object_path', None)
# get required values # get required values
if object_path is None: if object_path is None:
values = self._objects.values() values = ensure_list(self._objects.values())
else: else:
try: try:
value = self._objects[object_path] value = self._objects[object_path]
...@@ -3232,7 +3240,7 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -3232,7 +3240,7 @@ class ActionTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, **kw): def __init__(self, id_list, **kw):
# XXX It's look like ObjectTemplateItem __init__ # XXX It's look like ObjectTemplateItem __init__
BaseTemplateItem.__init__(self, id_list, **kw) BaseTemplateItem.__init__(self, id_list, **kw)
id_list = self._archive.keys() id_list = ensure_list(self._archive.keys())
self._archive.clear() self._archive.clear()
for id in id_list: for id in id_list:
self._archive["%s/%s" % ('portal_types', id)] = None self._archive["%s/%s" % ('portal_types', id)] = None
...@@ -3292,7 +3300,7 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -3292,7 +3300,7 @@ class ActionTemplateItem(ObjectTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
for id in self._archive.keys(): for id in self._archive:
url, value = id.split(' | ') url, value = id.split(' | ')
url = posixpath.split(url) url = posixpath.split(url)
obj = p.unrestrictedTraverse(url) obj = p.unrestrictedTraverse(url)
...@@ -3401,7 +3409,7 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -3401,7 +3409,7 @@ class ActionTemplateItem(ObjectTemplateItem):
# compatibility ? # compatibility ?
keys = [object_path] keys = [object_path]
else: else:
keys = self._archive.keys() keys = self._archive
for id in keys: for id in keys:
if '|' in id: if '|' in id:
relative_url, value = id.split(' | ') relative_url, value = id.split(' | ')
...@@ -3431,7 +3439,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -3431,7 +3439,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
for relative_url in self._archive.keys(): for relative_url in self._archive:
obj = p.unrestrictedTraverse("portal_types/%s" % obj = p.unrestrictedTraverse("portal_types/%s" %
relative_url.split('/', 1)[1]) relative_url.split('/', 1)[1])
# normalize url # normalize url
...@@ -3491,7 +3499,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -3491,7 +3499,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
if len(self._objects.keys()) == 0: if len(self._objects.keys()) == 0:
return return
path = self.__class__.__name__ path = self.__class__.__name__
for key in self._objects.keys(): for key in self._objects:
xml_data = self.generateXml(key) xml_data = self.generateXml(key)
if isinstance(xml_data, six.text_type): if isinstance(xml_data, six.text_type):
xml_data = xml_data.encode('utf-8') xml_data = xml_data.encode('utf-8')
...@@ -3559,7 +3567,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem): ...@@ -3559,7 +3567,7 @@ class PortalTypeRolesTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
keys = [object_path] keys = [object_path]
else: else:
keys = self._objects.keys() keys = self._objects
for roles_path in keys: for roles_path in keys:
path = 'portal_types/%s' % roles_path.split('/', 1)[1] path = 'portal_types/%s' % roles_path.split('/', 1)[1]
try: try:
...@@ -3573,7 +3581,7 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -3573,7 +3581,7 @@ class SitePropertyTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
for id in self._archive.keys(): for id in self._archive:
for property in p.propertyMap(): for property in p.propertyMap():
if property['id'] == id: if property['id'] == id:
obj = p.getProperty(id) obj = p.getProperty(id)
...@@ -3628,7 +3636,7 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -3628,7 +3636,7 @@ class SitePropertyTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
keys = [object_path] keys = [object_path]
else: else:
keys = self._archive.keys() keys = self._archive
for id in keys: for id in keys:
if p.hasProperty(id): if p.hasProperty(id):
p._delProperty(id) p._delProperty(id)
...@@ -3653,10 +3661,10 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -3653,10 +3661,10 @@ class SitePropertyTemplateItem(BaseTemplateItem):
return xml_data return xml_data
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0: if len(self._objects) == 0:
return return
xml_data = '<site_property>' xml_data = '<site_property>'
keys = self._objects.keys() keys = ensure_list(self._objects.keys())
keys.sort() keys.sort()
for path in keys: for path in keys:
xml_data += self.generateXml(path) xml_data += self.generateXml(path)
...@@ -3668,7 +3676,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3668,7 +3676,7 @@ class ModuleTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
for module_id in self._archive.keys(): for module_id in self._archive:
module = p.unrestrictedTraverse(module_id) module = p.unrestrictedTraverse(module_id)
mapping = {} mapping = {}
mapping['id'] = module.getId() mapping['id'] = module.getId()
...@@ -3682,8 +3690,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3682,8 +3690,7 @@ class ModuleTemplateItem(BaseTemplateItem):
def generateXml(self, path=None): def generateXml(self, path=None):
mapping = self._objects[path] mapping = self._objects[path]
xml_data = ['<module>'] xml_data = ['<module>']
keys = mapping.keys() for key in sorted(mapping):
for key in sorted(keys):
if key == 'permission_list': if key == 'permission_list':
# separe permission dict into xml # separe permission dict into xml
xml_data.append(' <%s>' % (key, )) xml_data.append(' <%s>' % (key, ))
...@@ -3725,7 +3732,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3725,7 +3732,7 @@ class ModuleTemplateItem(BaseTemplateItem):
if len(self._objects) == 0: if len(self._objects) == 0:
return return
path = self.__class__.__name__ path = self.__class__.__name__
keys = self._objects.keys() keys = ensure_list(self._objects.keys())
keys.sort() keys.sort()
for key in keys: for key in keys:
# export modules one by one # export modules one by one
...@@ -3800,7 +3807,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -3800,7 +3807,7 @@ class ModuleTemplateItem(BaseTemplateItem):
object_path = kw.get('object_path', None) object_path = kw.get('object_path', None)
trashbin = kw.get('trashbin', None) trashbin = kw.get('trashbin', None)
if object_path is None: if object_path is None:
keys = self._archive.keys() keys = self._archive
else: else:
keys = [object_path] keys = [object_path]
p = context.getPortalObject() p = context.getPortalObject()
...@@ -3848,7 +3855,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3848,7 +3855,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
modified_object_list = {} modified_object_list = {}
# fix key if necessary in installed bt for diff # fix key if necessary in installed bt for diff
extra_prefix = self.__class__.__name__ + '/' extra_prefix = self.__class__.__name__ + '/'
for key in installed_item._objects.keys(): for key in ensure_list(installed_item._objects.keys()):
if key.startswith(extra_prefix): if key.startswith(extra_prefix):
new_key = key[len(extra_prefix):] new_key = key[len(extra_prefix):]
installed_item._objects[new_key] = installed_item._objects[key] installed_item._objects[new_key] = installed_item._objects[key]
...@@ -3865,8 +3872,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3865,8 +3872,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
# Note: Magical way to have unique paths # Note: Magical way to have unique paths
modified_object_list[self._getKey(path)] = 'New', self.__class__.__name__[:-12] modified_object_list[self._getKey(path)] = 'New', self.__class__.__name__[:-12]
# get removed object # get removed object
old_keys = installed_item._objects.keys() for path in installed_item._objects:
for path in old_keys:
if path not in self._objects: if path not in self._objects:
# Note: Magical way to have unique paths # Note: Magical way to have unique paths
modified_object_list[self._getKey(path)] = 'Removed', self.__class__.__name__[:-12] modified_object_list[self._getKey(path)] = 'Removed', self.__class__.__name__[:-12]
...@@ -3876,7 +3882,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3876,7 +3882,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
need_reset = isinstance(self, FilesystemDocumentTemplateItem) need_reset = isinstance(self, FilesystemDocumentTemplateItem)
for key in self._objects.keys(): for key in self._objects:
# to achieve non data migration fresh installation parameters # to achieve non data migration fresh installation parameters
# differ from upgrade parameteres, so here the check have to be # differ from upgrade parameteres, so here the check have to be
# care of both cases # care of both cases
...@@ -3917,7 +3923,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3917,7 +3923,7 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive
if object_keys: if object_keys:
if isinstance(self, FilesystemDocumentTemplateItem): if isinstance(self, FilesystemDocumentTemplateItem):
self._resetDynamicModules() self._resetDynamicModules()
...@@ -3926,10 +3932,10 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem): ...@@ -3926,10 +3932,10 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0: if len(self._objects) == 0:
return return
extra_prefix = self.__class__.__name__ + '/' extra_prefix = self.__class__.__name__ + '/'
for key in self._objects.keys(): for key in self._objects:
obj = self._objects[key] obj = self._objects[key]
# BBB the prefix was put into each key in the previous implementation. # BBB the prefix was put into each key in the previous implementation.
if not key.startswith(extra_prefix): if not key.startswith(extra_prefix):
...@@ -3995,7 +4001,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem, ...@@ -3995,7 +4001,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem,
backward-compatibility backward-compatibility
""" """
def inner(self, *args, **kw): def inner(self, *args, **kw):
if self._is_already_migrated(getattr(self, object_dict_name).keys()): if self._is_already_migrated(getattr(self, object_dict_name)):
result = getattr(ObjectTemplateItem, method_name)(self, *args, **kw) result = getattr(ObjectTemplateItem, method_name)(self, *args, **kw)
else: else:
result = getattr(FilesystemDocumentTemplateItem, result = getattr(FilesystemDocumentTemplateItem,
...@@ -4037,7 +4043,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem, ...@@ -4037,7 +4043,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem,
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive
if self._is_already_migrated(object_keys): if self._is_already_migrated(object_keys):
ObjectTemplateItem.uninstall(self, *args, **kw) ObjectTemplateItem.uninstall(self, *args, **kw)
...@@ -4079,8 +4085,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem, ...@@ -4079,8 +4085,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem,
id_set = set(tool.objectIds()) id_set = set(tool.objectIds())
# careful, that dictionary will change # careful, that dictionary will change
class_id_list = migrate_object_dict.keys() for class_id in migrate_object_dict:
for class_id in class_id_list:
# If the Property Sheet already exists in ZODB, then skip it, # If the Property Sheet already exists in ZODB, then skip it,
# otherwise it should not be needed anymore once the deletion # otherwise it should not be needed anymore once the deletion
# code of the filesystem Property Sheets is enabled # code of the filesystem Property Sheets is enabled
...@@ -4145,7 +4150,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem, ...@@ -4145,7 +4150,7 @@ class FilesystemToZodbTemplateItem(FilesystemDocumentTemplateItem,
getattr(context.getPortalObject(), self._tool_id, None) is None): getattr(context.getPortalObject(), self._tool_id, None) is None):
return FilesystemDocumentTemplateItem.install(self, context, **kw) return FilesystemDocumentTemplateItem.install(self, context, **kw)
if not self._is_already_migrated(self._objects.keys()): if not self._is_already_migrated(self._objects):
self._migrateAllFromFilesystem(context, self._migrateAllFromFilesystem(context,
self._objects, self._objects,
self._archive, self._archive,
...@@ -4247,7 +4252,7 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem): ...@@ -4247,7 +4252,7 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
the source code and its state to load it is necessary for ZODB Components the source code and its state to load it is necessary for ZODB Components
and too much history would be exported (edit_workflow) and too much history would be exported (edit_workflow)
""" """
for wf_id in obj.workflow_history.keys(): for wf_id in ensure_list(obj.workflow_history.keys()):
if wf_id != 'component_validation_workflow': if wf_id != 'component_validation_workflow':
del obj.workflow_history[wf_id] del obj.workflow_history[wf_id]
continue continue
...@@ -4374,7 +4379,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem, ...@@ -4374,7 +4379,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem,
return return
# After running the migration script, update bt5 property accordingly # After running the migration script, update bt5 property accordingly
if not self._is_already_migrated(self._archive.keys()): if not self._is_already_migrated(self._archive):
document_id_list = self.getTemplateIdList() document_id_list = self.getTemplateIdList()
if document_id_list[0] not in getattr(context.getPortalObject(), if document_id_list[0] not in getattr(context.getPortalObject(),
'portal_components', ()): 'portal_components', ()):
...@@ -4391,7 +4396,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem, ...@@ -4391,7 +4396,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem,
automatically as the version must be set manually. This should not be an automatically as the version must be set manually. This should not be an
issue as there are not so many Documents in bt5... issue as there are not so many Documents in bt5...
""" """
if self._is_already_migrated(self._objects.keys()): if self._is_already_migrated(self._objects):
_ZodbComponentTemplateItem.install(self, context, **kw) _ZodbComponentTemplateItem.install(self, context, **kw)
else: else:
FilesystemDocumentTemplateItem.install(self, context, **kw) FilesystemDocumentTemplateItem.install(self, context, **kw)
...@@ -4469,8 +4474,7 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -4469,8 +4474,7 @@ class RoleTemplateItem(BaseTemplateItem):
else: # only show new roles else: # only show new roles
modified_object_list[role] = 'New', 'Role' modified_object_list[role] = 'New', 'Role'
# get removed roles # get removed roles
old_roles = installed_item._objects.keys() for role in installed_item._objects:
for role in old_roles:
if role not in self._objects: if role not in self._objects:
modified_object_list[role] = 'Removed', self.__class__.__name__[:-12] modified_object_list[role] = 'Removed', self.__class__.__name__[:-12]
return modified_object_list return modified_object_list
...@@ -4511,21 +4515,20 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -4511,21 +4515,20 @@ class RoleTemplateItem(BaseTemplateItem):
def trash(self, context, new_item, **kw): def trash(self, context, new_item, **kw):
p = context.getPortalObject() p = context.getPortalObject()
new_roles = {} new_roles = {}
for role in new_item._archive.keys(): for role in new_item._archive:
new_roles[role] = 1 new_roles[role] = 1
roles = {} roles = {}
for role in p.__ac_roles__: for role in p.__ac_roles__:
roles[role] = 1 roles[role] = 1
for role in self._archive.keys(): for role in self._archive:
if role in roles and role not in new_roles: if role in roles and role not in new_roles:
del roles[role] del roles[role]
p.__ac_roles__ = tuple(roles.keys()) p.__ac_roles__ = tuple(roles.keys())
# Function to generate XML Code Manually # Function to generate XML Code Manually
def generateXml(self): def generateXml(self):
role_list = self._objects.keys()
xml_data = '<role_list>' xml_data = '<role_list>'
for role in sorted(role_list): for role in sorted(self._objects):
xml_data += '\n <role>%s</role>' % (role,) xml_data += '\n <role>%s</role>' % (role,)
xml_data += '\n</role_list>' xml_data += '\n</role_list>'
return xml_data return xml_data
...@@ -4552,7 +4555,7 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem): ...@@ -4552,7 +4555,7 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
return return
catalog_key_list = list(getattr(catalog, self.key_list_attr, [])) catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
key_list = [] key_list = []
for key in self._archive.keys(): for key in self._archive:
if key in catalog_key_list: if key in catalog_key_list:
key_list.append(key) key_list.append(key)
elif not self.is_bt_for_diff: elif not self.is_bt_for_diff:
...@@ -4579,10 +4582,10 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem): ...@@ -4579,10 +4582,10 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
return return
catalog_key_list = list(getattr(catalog, self.key_list_attr, [])) catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
if len(self._objects.keys()) == 0: # needed because of pop() if len(self._objects) == 0: # needed because of pop()
return return
keys = [] keys = []
for k in self._objects.values().pop(): # because of list of list for k in ensure_list(self._objects.values()).pop(): # because of list of list
keys.append(k) keys.append(k)
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
...@@ -4605,7 +4608,7 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem): ...@@ -4605,7 +4608,7 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
if object_path is not None: if object_path is not None:
object_keys = [object_path] object_keys = [object_path]
else: else:
object_keys = self._archive.keys() object_keys = self._archive
for key in object_keys: for key in object_keys:
if key in catalog_key_list: if key in catalog_key_list:
catalog_key_list.remove(key) catalog_key_list.remove(key)
...@@ -4623,9 +4626,9 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem): ...@@ -4623,9 +4626,9 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
return xml_data return xml_data
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0: if len(self._objects) == 0:
return return
for name in self._objects.keys(): for name in self._objects:
path = self.__class__.__name__ path = self.__class__.__name__
xml_data = self.generateXml(path=name) xml_data = self.generateXml(path=name)
bta.addObject(xml_data, name=name, path=path) bta.addObject(xml_data, name=name, path=path)
...@@ -4737,7 +4740,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4737,7 +4740,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
localizer = context.getPortalObject().Localizer localizer = context.getPortalObject().Localizer
for lang_key in self._archive.keys(): for lang_key in self._archive:
if '|' in lang_key: if '|' in lang_key:
lang, catalog = lang_key.split(' | ') lang, catalog = lang_key.split(' | ')
else: # XXX backward compatibility else: # XXX backward compatibility
...@@ -4762,8 +4765,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4762,8 +4765,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
else: # new object else: # new object
modified_object_list[path] = 'New', self.__class__.__name__[:-12] modified_object_list[path] = 'New', self.__class__.__name__[:-12]
# get removed object # get removed object
old_keys = installed_item._objects.keys() for path in installed_item._objects:
for path in old_keys:
if path not in self._objects: if path not in self._objects:
modified_object_list[path] = 'Removed', self.__class__.__name__[:-12] modified_object_list[path] = 'Removed', self.__class__.__name__[:-12]
return modified_object_list return modified_object_list
...@@ -4847,13 +4849,13 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4847,13 +4849,13 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
# UGH! direct attribute access... but there is no real API to access # UGH! direct attribute access... but there is no real API to access
# all messages here. # all messages here.
messages = set(fake_message_catalog._messages.keys()) messages = set(fake_message_catalog._messages.keys())
messages.intersection_update(message_catalog._messages.keys()) messages.intersection_update(message_catalog._messages)
for message in messages: for message in messages:
# delete translations from the real catalog that are present in the # delete translations from the real catalog that are present in the
# fake one # fake one
fake_translations = fake_message_catalog.get_translations(message) fake_translations = fake_message_catalog.get_translations(message)
translations = message_catalog.get_translations(message) translations = message_catalog.get_translations(message)
for lang in fake_translations.keys(): for lang in fake_translations:
# XXX: should we check they're still the same before removing? # XXX: should we check they're still the same before removing?
translations.pop(lang, None) translations.pop(lang, None)
...@@ -4891,7 +4893,7 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4891,7 +4893,7 @@ class LocalRolesTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
for path in self._archive.keys(): for path in self._archive:
obj = p.unrestrictedTraverse(path.split('/', 1)[1]) obj = p.unrestrictedTraverse(path.split('/', 1)[1])
local_roles_dict = getattr(obj, '__ac_local_roles__', local_roles_dict = getattr(obj, '__ac_local_roles__',
{}) or {} {}) or {}
...@@ -5023,7 +5025,7 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -5023,7 +5025,7 @@ class LocalRolesTemplateItem(BaseTemplateItem):
if object_path is not None: if object_path is not None:
keys = [object_path] keys = [object_path]
else: else:
keys = self._objects.keys() keys = self._objects
for roles_path in keys: for roles_path in keys:
path = roles_path.split('/')[1:] path = roles_path.split('/')[1:]
# if document does not exists anymore longer, # if document does not exists anymore longer,
...@@ -5040,7 +5042,7 @@ class bt(dict): ...@@ -5040,7 +5042,7 @@ class bt(dict):
"""Fake 'bt' item to read bt/* files through BusinessTemplateArchive""" """Fake 'bt' item to read bt/* files through BusinessTemplateArchive"""
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
self[file_name] = file.read() self[file_name] = bytes2str(file.read())
class BusinessTemplate(XMLObject): class BusinessTemplate(XMLObject):
...@@ -5337,7 +5339,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5337,7 +5339,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
and catalog_method is not None: and catalog_method is not None:
if default_catalog.getId() == my_catalog.getId(): if default_catalog.getId() == my_catalog.getId():
# It is needed to update the catalog only if the default SQLCatalog is modified. # It is needed to update the catalog only if the default SQLCatalog is modified.
for method_id in catalog_method._objects.keys(): for method_id in catalog_method._objects:
if 'related' not in method_id: if 'related' not in method_id:
# must update catalog # must update catalog
return True return True
...@@ -6346,10 +6348,10 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6346,10 +6348,10 @@ Business Template is a set of definitions, such as skins, portal types and categ
type_list[type_id] = () type_list[type_id] = ()
# get same info for allowed portal types and hidden portal types # get same info for allowed portal types and hidden portal types
for allowed_ptype_id in allowed_content_type_list: for allowed_ptype_id in allowed_content_type_list:
if allowed_ptype_id not in type_list.keys(): if allowed_ptype_id not in type_list:
type_list.update(getChildPortalType(allowed_ptype_id)) type_list.update(getChildPortalType(allowed_ptype_id))
for hidden_ptype_id in hidden_content_type_list: for hidden_ptype_id in hidden_content_type_list:
if hidden_ptype_id not in type_list.keys(): if hidden_ptype_id not in type_list:
type_list.update(getChildPortalType(hidden_ptype_id)) type_list.update(getChildPortalType(hidden_ptype_id))
return type_list return type_list
...@@ -6372,15 +6374,15 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6372,15 +6374,15 @@ Business Template is a set of definitions, such as skins, portal types and categ
portal_dict[portal_type_id] = () portal_dict[portal_type_id] = ()
for allowed_type_id in allowed_content_type_list: for allowed_type_id in allowed_content_type_list:
if allowed_type_id not in portal_dict.keys(): if allowed_type_id not in portal_dict:
portal_dict.update(getChildPortalType(allowed_type_id)) portal_dict.update(getChildPortalType(allowed_type_id))
for hidden_type_id in hidden_content_type_list: for hidden_type_id in hidden_content_type_list:
if hidden_type_id not in portal_dict.keys(): if hidden_type_id not in portal_dict:
portal_dict.update(getChildPortalType(hidden_type_id)) portal_dict.update(getChildPortalType(hidden_type_id))
# construct portal type list, keep already present portal types # construct portal type list, keep already present portal types
for id in portal_dict.keys(): for id in portal_dict:
if id not in bt_portal_types_id_list: if id not in bt_portal_types_id_list:
bt_portal_types_id_list.append(id) bt_portal_types_id_list.append(id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment