Commit af791fc7 authored by Aurel's avatar Aurel

simplify the code for the install of skins layers


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4655 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9ed6634c
...@@ -885,75 +885,46 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -885,75 +885,46 @@ class SkinTemplateItem(ObjectTemplateItem):
ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw) ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
ObjectTemplateItem.install(self, context, trashbin, **kw)
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
if (getattr(self, 'template_format_version', 0)) == 1: p = context.getPortalObject()
ObjectTemplateItem.install(self, context, trashbin, **kw) # It is necessary to make sure that the sql connections in Z SQL Methods are valid.
p = context.getPortalObject() sql_connection_list = p.objectIds(spec=('Z MySQL Database Connection',))
ps = p.portal_skins for relative_url in self._archive.keys():
for skin_name, selection in ps.getSkinPaths(): folder = p.unrestrictedTraverse(relative_url)
new_selection = [] for object in folder.objectValues(spec=('Z SQL Method',)):
selection = selection.split(',') if object.connection_id not in sql_connection_list:
for relative_url in self._objects.keys(): object.connection_id = sql_connection_list[0]
# Add new folders into skin paths.
ps = p.portal_skins
for skin_name, selection in ps.getSkinPaths():
new_selection = []
selection = selection.split(',')
for relative_url in self._archive.keys():
if (getattr(self, 'template_format_version', 0)) == 1:
if update_dict.has_key(relative_url) or force: if update_dict.has_key(relative_url) or force:
if not force: if not force:
action = update_dict[relative_url] if update_dict[relative_url] == 'nothing':
if action == 'nothing':
continue continue
object_path = relative_url.split('/') object = self._objects[relative_url]
if len(object_path) > 2: else:
continue # not a skin folder
object = self._objects[relative_url]
skin_id = object_path[1]
if hasattr(aq_base(object), 'getProperty'):
selection_list = object.getProperty('business_template_registered_skin_selections', None)
else:
continue
if selection_list is None or skin_name in selection_list:
if skin_id not in selection and skin_id not in new_selection:
new_selection.append(skin_id)
new_selection.extend(selection)
# sort the layer according to skin priorities
new_selection.sort(lambda a, b : cmp( # separate functions here
b in ps.objectIds() and ps[b].getProperty(
'business_template_skin_layer_priority', 0) or 0,
a in ps.objectIds() and ps[a].getProperty(
'business_template_skin_layer_priority', 0) or 0))
ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1)
# Make sure that skin data is up-to-date (see CMFCore/Skinnable.py).
p.changeSkin(None)
else:
ObjectTemplateItem.install(self, context, trashbin, **kw)
p = context.getPortalObject()
# It is necessary to make sure that the sql connections in Z SQL Methods are valid.
sql_connection_list = p.objectIds(spec=('Z MySQL Database Connection',))
for relative_url in self._archive.keys():
folder = p.unrestrictedTraverse(relative_url)
for object in folder.objectValues(spec=('Z SQL Method',)):
if object.connection_id not in sql_connection_list:
object.connection_id = sql_connection_list[0]
# Add new folders into skin paths.
ps = p.portal_skins
for skin_name, selection in ps.getSkinPaths():
new_selection = []
selection = selection.split(',')
for relative_url in self._archive.keys():
object = self._archive[relative_url] object = self._archive[relative_url]
skin_id = relative_url.split('/')[-1] skin_id = relative_url.split('/')[-1]
selection_list = object.getProperty('business_template_registered_skin_selections', None) selection_list = object.getProperty('business_template_registered_skin_selections', None)
if selection_list is None or skin_name in selection_list: if selection_list is None or skin_name in selection_list:
if skin_id not in selection: if skin_id not in selection:
new_selection.append(skin_id) new_selection.append(skin_id)
new_selection.extend(selection) new_selection.extend(selection)
# sort the layer according to skin priorities # sort the layer according to skin priorities
new_selection.sort(lambda a, b : cmp( new_selection.sort(lambda a, b : cmp(
b in ps.objectIds() and ps[b].getProperty( b in ps.objectIds() and ps[b].getProperty(
'business_template_skin_layer_priority', 0) or 0, 'business_template_skin_layer_priority', 0) or 0,
a in ps.objectIds() and ps[a].getProperty( a in ps.objectIds() and ps[a].getProperty(
'business_template_skin_layer_priority', 0) or 0)) 'business_template_skin_layer_priority', 0) or 0))
ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1) ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1)
# Make sure that skin data is up-to-date (see CMFCore/Skinnable.py). # Make sure that skin data is up-to-date (see CMFCore/Skinnable.py).
p.changeSkin(None) p.changeSkin(None)
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
# Remove folders from skin paths. # Remove folders from skin paths.
......
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