Commit b4f796a9 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Fixes typo that prevents to replace a business template that uses files.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4270 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 080a4173
...@@ -98,7 +98,7 @@ def removeAll(entry): ...@@ -98,7 +98,7 @@ def removeAll(entry):
class BusinessTemplateArchive: class BusinessTemplateArchive:
""" """
This is the base class for all Business Template archives This is the base class for all Business Template archives
""" """
def __init__(self, creation=0, importing=0, file=None, path=None, **kw): def __init__(self, creation=0, importing=0, file=None, path=None, **kw):
if creation: if creation:
...@@ -111,14 +111,14 @@ class BusinessTemplateArchive: ...@@ -111,14 +111,14 @@ class BusinessTemplateArchive:
def addObject(self, *kw): def addObject(self, *kw):
pass pass
def finishCreation(self, **kw): def finishCreation(self, **kw):
pass pass
class BusinessTemplateFolder(BusinessTemplateArchive): class BusinessTemplateFolder(BusinessTemplateArchive):
""" """
Class archiving businnes template into a folder tree Class archiving businnes template into a folder tree
""" """
def _initCreation(self, path): def _initCreation(self, path):
self.path = path self.path = path
try: try:
...@@ -164,7 +164,7 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -164,7 +164,7 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
klass._importFile(file_name, file) klass._importFile(file_name, file)
# close file # close file
file.close() file.close()
class BusinessTemplateTarball(BusinessTemplateArchive): class BusinessTemplateTarball(BusinessTemplateArchive):
""" """
Class archiving businnes template into a tarball file Class archiving businnes template into a tarball file
...@@ -208,7 +208,7 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -208,7 +208,7 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
def importFiles(self, klass, **kw): def importFiles(self, klass, **kw):
""" """
Import all file from the archive to the site Import all file from the archive to the site
""" """
class_name = klass.__class__.__name__ class_name = klass.__class__.__name__
self.f.seek(0) self.f.seek(0)
data = GzipFile(fileobj=self.f).read() data = GzipFile(fileobj=self.f).read()
...@@ -256,18 +256,18 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -256,18 +256,18 @@ class BaseTemplateItem(Implicit, Persistent):
def diff(self, **kw): def diff(self, **kw):
return '' return ''
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
pass pass
def importFile(self, bta, **kw): def importFile(self, bta, **kw):
bta.importFiles(klass=self) bta.importFiles(klass=self)
class ObjectTemplateItem(BaseTemplateItem): class ObjectTemplateItem(BaseTemplateItem):
""" """
This class is used for generic objects and as a subclass. This class is used for generic objects and as a subclass.
""" """
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)
if tool_id is not None: if tool_id is not None:
...@@ -296,7 +296,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -296,7 +296,7 @@ class ObjectTemplateItem(BaseTemplateItem):
sub_list = {} sub_list = {}
for id in id_list: for id in id_list:
relative_url = '/'.join([url,id]) relative_url = '/'.join([url,id])
object = p.unrestrictedTraverse(relative_url) object = p.unrestrictedTraverse(relative_url)
object = object._getCopy(context) object = object._getCopy(context)
id_list = object.objectIds() id_list = object.objectIds()
if hasattr(object, 'groups'): if hasattr(object, 'groups'):
...@@ -379,11 +379,11 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -379,11 +379,11 @@ class ObjectTemplateItem(BaseTemplateItem):
object.manage_afterClone(object) object.manage_afterClone(object)
object.wl_clearLocks() object.wl_clearLocks()
if object.meta_type in ('Z SQL Method',): if object.meta_type in ('Z SQL Method',):
# It is necessary to make sure that the sql connection # It is necessary to make sure that the sql connection
# in this method is valid. # in this method is valid.
sql_connection_list = portal.objectIds(spec=('Z MySQL Database Connection',)) sql_connection_list = portal.objectIds(spec=('Z MySQL Database Connection',))
if object.connection_id not in sql_connection_list: if object.connection_id not in sql_connection_list:
object.connection_id = sql_connection_list[0] object.connection_id = sql_connection_list[0]
# now put original order group # now put original order group
for path in groups.keys(): for path in groups.keys():
object = portal.unrestrictedTraverse(path.split('/')[2:]) object = portal.unrestrictedTraverse(path.split('/')[2:])
...@@ -405,7 +405,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -405,7 +405,7 @@ class ObjectTemplateItem(BaseTemplateItem):
object.manage_afterClone(object) object.manage_afterClone(object)
object.wl_clearLocks() object.wl_clearLocks()
if object.meta_type in ('Z SQL Method',): if object.meta_type in ('Z SQL Method',):
# It is necessary to make sure that the sql connection # It is necessary to make sure that the sql connection
# in this method is valid. # in this method is valid.
sql_connection_list = portal.objectIds( sql_connection_list = portal.objectIds(
spec=('Z MySQL Database Connection',)) spec=('Z MySQL Database Connection',))
...@@ -426,12 +426,12 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -426,12 +426,12 @@ class ObjectTemplateItem(BaseTemplateItem):
if object_id in container.objectIds(): if object_id in container.objectIds():
container.manage_delObjects([object_id]) container.manage_delObjects([object_id])
except NotFound: except NotFound:
pass pass
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def _compareObjects(self, object1, object2, btsave_object_included=0): def _compareObjects(self, object1, object2, btsave_object_included=0):
""" """
Execute a diff between 2 objects, Execute a diff between 2 objects,
and return a string diff. and return a string diff.
""" """
xml_dict = { xml_dict = {
...@@ -456,7 +456,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -456,7 +456,7 @@ class ObjectTemplateItem(BaseTemplateItem):
if len(diff_list) == 3: if len(diff_list) == 3:
if '_btsave_' in diff_list[1]: if '_btsave_' in diff_list[1]:
diff_list = [] diff_list = []
# Return string # Return string
result = '%s' % ''.join(diff_list) result = '%s' % ''.join(diff_list)
return result return result
...@@ -525,7 +525,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -525,7 +525,7 @@ class ObjectTemplateItem(BaseTemplateItem):
(new_object.absolute_url(), (new_object.absolute_url(),
btsave_object.absolute_url()) btsave_object.absolute_url())
if verbose == 1: if verbose == 1:
result += tmp_diff result += tmp_diff
result += '%s\n' % ('-'*80) result += '%s\n' % ('-'*80)
return result return result
...@@ -544,7 +544,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -544,7 +544,7 @@ class PathTemplateItem(ObjectTemplateItem):
def _resolvePath(self, folder, relative_url_list, id_list): def _resolvePath(self, folder, relative_url_list, id_list):
""" """
This method calls itself recursively. This method calls itself recursively.
The folder is the current object which contains sub-objects. The folder is the current object which contains sub-objects.
The list of ids are path components. If the list is empty, The list of ids are path components. If the list is empty,
the current folder is valid. the current folder is valid.
...@@ -572,7 +572,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -572,7 +572,7 @@ class PathTemplateItem(ObjectTemplateItem):
object.uid = None object.uid = None
self._objects[relative_url] = object self._objects[relative_url] = object
object.wl_clearLocks() object.wl_clearLocks()
class CategoryTemplateItem(ObjectTemplateItem): class CategoryTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, tool_id='portal_categories', **kw): def __init__(self, id_list, tool_id='portal_categories', **kw):
...@@ -583,7 +583,7 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -583,7 +583,7 @@ class CategoryTemplateItem(ObjectTemplateItem):
sub_list = {} sub_list = {}
for id in id_list: for id in id_list:
relative_url = '/'.join([url,id]) relative_url = '/'.join([url,id])
object = p.unrestrictedTraverse(relative_url) object = p.unrestrictedTraverse(relative_url)
object_copy = object._getCopy(context) object_copy = object._getCopy(context)
include_sub_categories = object.getProperty('business_template_include_sub_categories', 0) include_sub_categories = object.getProperty('business_template_include_sub_categories', 0)
id_list = object_copy.objectIds() id_list = object_copy.objectIds()
...@@ -591,7 +591,7 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -591,7 +591,7 @@ class CategoryTemplateItem(ObjectTemplateItem):
self.build_sub_objects(context, id_list, relative_url) self.build_sub_objects(context, id_list, relative_url)
object_copy.manage_delObjects(list(id_list)) object_copy.manage_delObjects(list(id_list))
else: else:
object_copy.manage_delObjects(list(id_list)) object_copy.manage_delObjects(list(id_list))
if hasattr(aq_base(object_copy), 'uid'): if hasattr(aq_base(object_copy), 'uid'):
object_copy.uid = None object_copy.uid = None
self._objects[relative_url] = object_copy self._objects[relative_url] = object_copy
...@@ -691,7 +691,7 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -691,7 +691,7 @@ class SkinTemplateItem(ObjectTemplateItem):
# sort the layer according to skin priorities # sort the layer according to skin priorities
new_selection.sort(lambda a, b : cmp( # separate functions here new_selection.sort(lambda a, b : cmp( # separate functions here
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)
...@@ -722,7 +722,7 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -722,7 +722,7 @@ class SkinTemplateItem(ObjectTemplateItem):
# 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)
...@@ -827,10 +827,10 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -827,10 +827,10 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
xml_data += os.linesep+' <chain>' xml_data += os.linesep+' <chain>'
xml_data += os.linesep+' <type>%s</type>' %(key,) xml_data += os.linesep+' <type>%s</type>' %(key,)
xml_data += os.linesep+' <workflow>%s</workflow>' %(self._workflow_chain_archive[key],) xml_data += os.linesep+' <workflow>%s</workflow>' %(self._workflow_chain_archive[key],)
xml_data += os.linesep+' </chain>' xml_data += os.linesep+' </chain>'
xml_data += os.linesep+'</workflow_chain>' xml_data += os.linesep+'</workflow_chain>'
bta.addObject(object=xml_data, name='workflow_chain_type', path=root_path) bta.addObject(object=xml_data, name='workflow_chain_type', path=root_path)
def install(self, context, **kw): def install(self, context, **kw):
ObjectTemplateItem.install(self, context, **kw) ObjectTemplateItem.install(self, context, **kw)
# We now need to setup the list of workflows corresponding to # We now need to setup the list of workflows corresponding to
...@@ -839,10 +839,10 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -839,10 +839,10 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
# Set the default chain to the empty string is probably the # Set the default chain to the empty string is probably the
# best solution, by default it is 'default_workflow', wich is # best solution, by default it is 'default_workflow', wich is
# not very usefull # not very usefull
default_chain = '' default_chain = ''
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
objects = self._objects.values() objects = self._objects.values()
else: else:
objects = self._archive.values() objects = self._archive.values()
for object in objects: for object in objects:
portal_type = object.id portal_type = object.id
...@@ -859,7 +859,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -859,7 +859,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
(default_chain, chain_dict) = self._getChainByType(self) (default_chain, chain_dict) = self._getChainByType(self)
chain = chain_dict['chain_%s' % object_id] chain = chain_dict['chain_%s' % object_id]
# Backup the portal type # Backup the portal type
backup_id = ObjectTemplateItem._backupObject(self, container, backup_id = ObjectTemplateItem._backupObject(self, container,
object_id, **kw) object_id, **kw)
# Restore the chain to the backuped portal type # Restore the chain to the backuped portal type
(default_chain, chain_dict) = self._getChainByType(self) (default_chain, chain_dict) = self._getChainByType(self)
...@@ -869,7 +869,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -869,7 +869,7 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
def diff(self, verbose=0, **kw): def diff(self, verbose=0, **kw):
""" """
Make a diff between portal type. Make a diff between portal type.
Also compare the workflow chain. Also compare the workflow chain.
""" """
# Compare XML portal type # Compare XML portal type
...@@ -994,7 +994,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -994,7 +994,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
xml_data += os.linesep+'</catalog_method>' xml_data += os.linesep+'</catalog_method>'
f.write(str(xml_data)) f.write(str(xml_data))
f.close() f.close()
def install(self, context, **kw): def install(self, context, **kw):
ObjectTemplateItem.install(self, context, **kw) ObjectTemplateItem.install(self, context, **kw)
try: try:
...@@ -1120,7 +1120,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -1120,7 +1120,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
catalog.sql_clear_catalog = tuple(sql_clear_catalog) catalog.sql_clear_catalog = tuple(sql_clear_catalog)
ObjectTemplateItem.uninstall(self, context, **kw) ObjectTemplateItem.uninstall(self, context, **kw)
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
if not '.catalog_keys' in file_name and not '.filter_instance' in file_name: if not '.catalog_keys' in file_name and not '.filter_instance' in file_name:
# just import xml object # just import xml object
...@@ -1137,7 +1137,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -1137,7 +1137,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
id = string.split(name, '.')[0] id = string.split(name, '.')[0]
xml = parse(file) xml = parse(file)
method_list = xml.getElementsByTagName('method') method_list = xml.getElementsByTagName('method')
for method in method_list: for method in method_list:
key = method.getElementsByTagName('key')[0].childNodes[0].data key = method.getElementsByTagName('key')[0].childNodes[0].data
value = method.getElementsByTagName('value')[0].childNodes[0].data value = method.getElementsByTagName('value')[0].childNodes[0].data
key = str(key) key = str(key)
...@@ -1211,7 +1211,7 @@ class ActionTemplateItem(ObjectTemplateItem): ...@@ -1211,7 +1211,7 @@ class ActionTemplateItem(ObjectTemplateItem):
raise NotFound, 'Action %r not found' %(id,) raise NotFound, 'Action %r not found' %(id,)
def install(self, context, **kw): def install(self, context, **kw):
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
p = context.getPortalObject() p = context.getPortalObject()
for id in self._objects.keys(): for id in self._objects.keys():
path = id.split(os.sep) path = id.split(os.sep)
...@@ -1349,7 +1349,7 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -1349,7 +1349,7 @@ class SitePropertyTemplateItem(BaseTemplateItem):
xml_data += os.linesep+' </property>' xml_data += os.linesep+' </property>'
xml_data += os.linesep+'</site_property>' xml_data += os.linesep+'</site_property>'
bta.addObject(object=xml_data, name='properties', path=root_path) bta.addObject(object=xml_data, name='properties', path=root_path)
class ModuleTemplateItem(BaseTemplateItem): class ModuleTemplateItem(BaseTemplateItem):
def diff(self, max_deep=1, **kw): def diff(self, max_deep=1, **kw):
...@@ -1378,7 +1378,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -1378,7 +1378,7 @@ class ModuleTemplateItem(BaseTemplateItem):
keys.sort() keys.sort()
for id in keys: for id in keys:
dict = self._objects[id] dict = self._objects[id]
xml_data = '<module>' xml_data = '<module>'
for key in dict.keys(): for key in dict.keys():
if key =='permission_list': if key =='permission_list':
# separe permission dict into xml # separe permission dict into xml
...@@ -1392,13 +1392,13 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -1392,13 +1392,13 @@ class ModuleTemplateItem(BaseTemplateItem):
xml_data += os.linesep+' <role>%s</role>' %(role) xml_data += os.linesep+' <role>%s</role>' %(role)
xml_data += os.linesep+' </permission>' xml_data += os.linesep+' </permission>'
xml_data += os.linesep+' </%s>' %(key,) xml_data += os.linesep+' </%s>' %(key,)
else: else:
xml_data += os.linesep+' <%s>%s</%s>' %(key, dict[key], key) xml_data += os.linesep+' <%s>%s</%s>' %(key, dict[key], key)
xml_data += os.linesep+'</module>' xml_data += os.linesep+'</module>'
bta.addObject(object=xml_data, name=id, path=path) bta.addObject(object=xml_data, name=id, path=path)
def install(self, context, **kw): def install(self, context, **kw):
portal = context.getPortalObject() portal = context.getPortalObject()
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
items = self._objects.items() items = self._objects.items()
else: else:
...@@ -1450,7 +1450,7 @@ class ModuleTemplateItem(BaseTemplateItem): ...@@ -1450,7 +1450,7 @@ class ModuleTemplateItem(BaseTemplateItem):
self._objects[file_name[:-4]] = dict self._objects[file_name[:-4]] = dict
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
id_list = p.objectIds() id_list = p.objectIds()
...@@ -1496,7 +1496,7 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -1496,7 +1496,7 @@ class DocumentTemplateItem(BaseTemplateItem):
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
for id in self._archive.keys(): for id in self._archive.keys():
globals()[self.local_file_importer_name](id) globals()[self.local_file_remover_name](id)
BaseTemplateItem.uninstall(self, context, **kw) BaseTemplateItem.uninstall(self, context, **kw)
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
...@@ -1510,7 +1510,7 @@ class DocumentTemplateItem(BaseTemplateItem): ...@@ -1510,7 +1510,7 @@ class DocumentTemplateItem(BaseTemplateItem):
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
text = file.read() text = file.read()
self._objects[file_name[:-3]]=text self._objects[file_name[:-3]]=text
class PropertySheetTemplateItem(DocumentTemplateItem): class PropertySheetTemplateItem(DocumentTemplateItem):
local_file_reader_name = 'readLocalPropertySheet' local_file_reader_name = 'readLocalPropertySheet'
...@@ -1518,7 +1518,7 @@ class PropertySheetTemplateItem(DocumentTemplateItem): ...@@ -1518,7 +1518,7 @@ class PropertySheetTemplateItem(DocumentTemplateItem):
local_file_importer_name = 'importLocalPropertySheet' local_file_importer_name = 'importLocalPropertySheet'
local_file_remover_name = 'removeLocalPropertySheet' local_file_remover_name = 'removeLocalPropertySheet'
class ExtensionTemplateItem(DocumentTemplateItem): class ExtensionTemplateItem(DocumentTemplateItem):
local_file_reader_name = 'readLocalExtension' local_file_reader_name = 'readLocalExtension'
local_file_writer_name = 'writeLocalExtension' local_file_writer_name = 'writeLocalExtension'
...@@ -1551,12 +1551,12 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -1551,12 +1551,12 @@ class RoleTemplateItem(BaseTemplateItem):
p = context.getPortalObject() p = context.getPortalObject()
roles = {} roles = {}
for role in p.__ac_roles__: for role in p.__ac_roles__:
roles[role] = 1 roles[role] = 1
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
role_list = self._objects.keys() role_list = self._objects.keys()
else: else:
role_list = self._archive.keys() role_list = self._archive.keys()
for role in role_list: for role in role_list:
roles[role] = 1 roles[role] = 1
p.__ac_roles__ = tuple(roles.keys()) p.__ac_roles__ = tuple(roles.keys())
...@@ -1604,7 +1604,7 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -1604,7 +1604,7 @@ class RoleTemplateItem(BaseTemplateItem):
xml_data += os.linesep+' <role>%s</role>' %(role) xml_data += os.linesep+' <role>%s</role>' %(role)
xml_data += os.linesep+'</role_list>' xml_data += os.linesep+'</role_list>'
bta.addObject(object=xml_data, name=path, path=None,) bta.addObject(object=xml_data, name=path, path=None,)
class CatalogResultKeyTemplateItem(BaseTemplateItem): class CatalogResultKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
...@@ -1635,7 +1635,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem): ...@@ -1635,7 +1635,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
list.append(str(value)) list.append(str(value))
self._objects[file_name[:-4]] = list self._objects[file_name[:-4]] = list
def install(self, context, **kw): def install(self, context, **kw):
try: try:
catalog = context.portal_catalog.getSQLCatalog() catalog = context.portal_catalog.getSQLCatalog()
except KeyError: except KeyError:
...@@ -1643,7 +1643,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem): ...@@ -1643,7 +1643,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
if catalog is None: if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available') LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return return
sql_search_result_keys = list(catalog.sql_search_result_keys) sql_search_result_keys = list(catalog.sql_search_result_keys)
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
if len(self._objects.keys()) == 0: # needed because of pop() if len(self._objects.keys()) == 0: # needed because of pop()
...@@ -1652,7 +1652,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem): ...@@ -1652,7 +1652,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
for k in self._objects.values().pop(): # because of list of list for k in self._objects.values().pop(): # because of list of list
keys.append(k) keys.append(k)
else: else:
keys = self._archive.keys() keys = self._archive.keys()
for key in keys: for key in keys:
if key not in sql_search_result_keys: if key not in sql_search_result_keys:
sql_search_result_keys.append(key) sql_search_result_keys.append(key)
...@@ -1679,14 +1679,14 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem): ...@@ -1679,14 +1679,14 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
return return
path = os.path.join(bta.path, self.__class__.__name__) path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path) bta.addFolder(name=path)
for path in self._objects.keys(): for path in self._objects.keys():
object=self._objects[path] object=self._objects[path]
xml_data = '<key_list>' xml_data = '<key_list>'
for key in object: for key in object:
xml_data += os.linesep+' <key>%s</key>' %(key) xml_data += os.linesep+' <key>%s</key>' %(key)
xml_data += os.linesep+'</key_list>' xml_data += os.linesep+'</key_list>'
bta.addObject(object=xml_data, name=path, path=None) bta.addObject(object=xml_data, name=path, path=None)
class CatalogRelatedKeyTemplateItem(BaseTemplateItem): class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
...@@ -1717,7 +1717,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem): ...@@ -1717,7 +1717,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
list.append(str(value)) list.append(str(value))
self._objects[file_name[:-4]] = list self._objects[file_name[:-4]] = list
def install(self, context, **kw): def install(self, context, **kw):
try: try:
catalog = context.portal_catalog.getSQLCatalog() catalog = context.portal_catalog.getSQLCatalog()
except KeyError: except KeyError:
...@@ -1725,7 +1725,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem): ...@@ -1725,7 +1725,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
if catalog is None: if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available') LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return return
sql_catalog_related_keys = list(catalog.sql_catalog_related_keys) sql_catalog_related_keys = list(catalog.sql_catalog_related_keys)
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
if len(self._objects.keys()) == 0: # needed because of pop() if len(self._objects.keys()) == 0: # needed because of pop()
...@@ -1734,12 +1734,12 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem): ...@@ -1734,12 +1734,12 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
for k in self._objects.values().pop(): # because of list of list for k in self._objects.values().pop(): # because of list of list
keys.append(k) keys.append(k)
else: else:
keys = self._archive.keys() keys = self._archive.keys()
for key in keys: for key in keys:
if key not in sql_catalog_related_keys: if key not in sql_catalog_related_keys:
sql_catalog_related_keys.append(key) sql_catalog_related_keys.append(key)
catalog.sql_catalog_related_keys = sql_catalog_related_keys catalog.sql_catalog_related_keys = sql_catalog_related_keys
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
try: try:
catalog = context.portal_catalog.getSQLCatalog() catalog = context.portal_catalog.getSQLCatalog()
...@@ -1765,7 +1765,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem): ...@@ -1765,7 +1765,7 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
xml_data = '<key_list>' xml_data = '<key_list>'
for key in object: for key in object:
xml_data += os.linesep+' <key>%s</key>' %(key) xml_data += os.linesep+' <key>%s</key>' %(key)
xml_data += os.linesep+'</key_list>' xml_data += os.linesep+'</key_list>'
bta.addObject(object=xml_data, name=path, path=None) bta.addObject(object=xml_data, name=path, path=None)
class CatalogResultTableTemplateItem(BaseTemplateItem): class CatalogResultTableTemplateItem(BaseTemplateItem):
...@@ -1806,7 +1806,7 @@ class CatalogResultTableTemplateItem(BaseTemplateItem): ...@@ -1806,7 +1806,7 @@ class CatalogResultTableTemplateItem(BaseTemplateItem):
if catalog is None: if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available') LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return return
sql_search_tables = list(catalog.sql_search_tables) sql_search_tables = list(catalog.sql_search_tables)
if (getattr(self, 'template_format_version', 0)) == 1: if (getattr(self, 'template_format_version', 0)) == 1:
if len(self._objects.keys()) == 0: # needed because of pop() if len(self._objects.keys()) == 0: # needed because of pop()
...@@ -1815,7 +1815,7 @@ class CatalogResultTableTemplateItem(BaseTemplateItem): ...@@ -1815,7 +1815,7 @@ class CatalogResultTableTemplateItem(BaseTemplateItem):
for k in self._objects.values().pop(): # because of list of list for k in self._objects.values().pop(): # because of list of list
keys.append(k) keys.append(k)
else: else:
keys = self._archive.keys() keys = self._archive.keys()
for key in keys: for key in keys:
if key not in sql_search_tables: if key not in sql_search_tables:
sql_search_tables.append(key) sql_search_tables.append(key)
...@@ -1846,15 +1846,15 @@ class CatalogResultTableTemplateItem(BaseTemplateItem): ...@@ -1846,15 +1846,15 @@ class CatalogResultTableTemplateItem(BaseTemplateItem):
xml_data = '<key_list>' xml_data = '<key_list>'
for key in object: for key in object:
xml_data += os.linesep+' <key>%s</key>' %(key) xml_data += os.linesep+' <key>%s</key>' %(key)
xml_data += os.linesep+'</key_list>' xml_data += os.linesep+'</key_list>'
bta.addObject(object=xml_data, name=path, path=None) bta.addObject(object=xml_data, name=path, path=None)
class MessageTranslationTemplateItem(BaseTemplateItem): class MessageTranslationTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
localizer = context.getPortalObject().Localizer localizer = context.getPortalObject().Localizer
for lang in self._archive.keys(): for lang in self._archive.keys():
# Export only erp5_ui at the moment. # Export only erp5_ui at the moment.
# This is safer against information leak. # This is safer against information leak.
for catalog in ('erp5_ui', ): for catalog in ('erp5_ui', ):
path = os.path.join(lang, catalog) path = os.path.join(lang, catalog)
...@@ -1900,9 +1900,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -1900,9 +1900,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
text = file.read() text = file.read()
self._objects[file_name[:-3]]=text self._objects[file_name[:-3]]=text
class BusinessTemplate(XMLObject): class BusinessTemplate(XMLObject):
""" """
A business template allows to construct ERP5 modules A business template allows to construct ERP5 modules
in part or completely. Each object are separated from its in part or completely. Each object are separated from its
...@@ -1932,13 +1932,13 @@ class BusinessTemplate(XMLObject): ...@@ -1932,13 +1932,13 @@ class BusinessTemplate(XMLObject):
- document/propertysheet/extension/test definition - document/propertysheet/extension/test definition
- copy of the local file - copy of the local file
- message transalation definition - message transalation definition
- .po file - .po file
The Business Template properties are exported to the bt folder with The Business Template properties are exported to the bt folder with
one property per file one property per file
Technology: Technology:
- download a gzip file or folder tree (from the web, from a CVS repository, - download a gzip file or folder tree (from the web, from a CVS repository,
...@@ -1949,11 +1949,11 @@ class BusinessTemplate(XMLObject): ...@@ -1949,11 +1949,11 @@ class BusinessTemplate(XMLObject):
Use case: Use case:
- install core ERP5 (the minimum) - install core ERP5 (the minimum)
- go to "BT" menu. Import BT. Select imported BT. Click install. - go to "BT" menu. Import BT. Select imported BT. Click install.
- go to "BT" menu. Create new BT. - go to "BT" menu. Create new BT.
Define BT elements (workflow, methods, attributes, etc.). Define BT elements (workflow, methods, attributes, etc.).
Build BT and export or save it Build BT and export or save it
Done. Done.
""" """
...@@ -2095,7 +2095,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2095,7 +2095,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
# Make sure that the installation state is "not installed". # Make sure that the installation state is "not installed".
if portal_workflow.getStatusOf( if portal_workflow.getStatusOf(
'business_template_installation_workflow', self) is not None: 'business_template_installation_workflow', self) is not None:
# XXX Not good to access the attribute directly, # XXX Not good to access the attribute directly,
# but there is no API for clearing the history. # but there is no API for clearing the history.
self.workflow_history[ self.workflow_history[
'business_template_installation_workflow'] = None 'business_template_installation_workflow'] = None
...@@ -2107,13 +2107,13 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2107,13 +2107,13 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
# Make sure that everything is sane. # Make sure that everything is sane.
self.clean() self.clean()
# XXX Trim down the history to prevent it from bloating the bt5 file. # XXX Trim down the history to prevent it from bloating the bt5 file.
# XXX Is there any better way to shrink the size??? # XXX Is there any better way to shrink the size???
# XXX Is it still necessary as it is not saved in new bt format ?? # XXX Is it still necessary as it is not saved in new bt format ??
portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow = getToolByName(self, 'portal_workflow')
wf_id_list = portal_workflow.getChainFor(self) wf_id_list = portal_workflow.getChainFor(self)
original_history_dict = {} original_history_dict = {}
for wf_id in wf_id_list: for wf_id in wf_id_list:
history = portal_workflow.getHistoryOf(wf_id, self) history = portal_workflow.getHistoryOf(wf_id, self)
if history is not None and len(history) > 30: if history is not None and len(history) > 30:
...@@ -2173,7 +2173,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2173,7 +2173,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
Publish in a format or another Publish in a format or another
""" """
return self.portal_templates.publish(self, url, username=username, return self.portal_templates.publish(self, url, username=username,
password=password) password=password)
def update(self): def update(self):
...@@ -2185,7 +2185,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2185,7 +2185,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
def _install(self, **kw): def _install(self, **kw):
installed_bt = self.portal_templates.getInstalledBusinessTemplate( installed_bt = self.portal_templates.getInstalledBusinessTemplate(
self.getTitle()) self.getTitle())
LOG('Business Template install', 0, LOG('Business Template install', 0,
'self = %r, installed_bt = %r' % (self, installed_bt)) 'self = %r, installed_bt = %r' % (self, installed_bt))
if installed_bt is not None: if installed_bt is not None:
...@@ -2199,7 +2199,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2199,7 +2199,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
for item_name in self._item_name_list: for item_name in self._item_name_list:
item = getattr(self, item_name) item = getattr(self, item_name)
if item is not None: if item is not None:
item.install(local_configuration) item.install(local_configuration)
# It is better to clear cache because the installation of a template # It is better to clear cache because the installation of a template
# adds many new things into the portal. # adds many new things into the portal.
clearCache() clearCache()
...@@ -2210,7 +2210,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2210,7 +2210,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
For install based on paramaters provided in **kw For install based on paramaters provided in **kw
""" """
return self._install(**kw) return self._install(**kw)
install = WorkflowMethod(install) install = WorkflowMethod(install)
security.declareProtected(Permissions.ManagePortal, 'reinstall') security.declareProtected(Permissions.ManagePortal, 'reinstall')
...@@ -2224,9 +2224,9 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2224,9 +2224,9 @@ Business Template is a set of definitions, such as skins, portal types and categ
security.declareProtected(Permissions.ManagePortal, 'trash') security.declareProtected(Permissions.ManagePortal, 'trash')
def trash(self, new_bt, **kw): def trash(self, new_bt, **kw):
""" """
Trash unnecessary items before upgrading to a new business Trash unnecessary items before upgrading to a new business
template. template.
This is similar to uninstall, but different in that this does This is similar to uninstall, but different in that this does
not remove all items. not remove all items.
""" """
# Update local dictionary containing all setup parameters # Update local dictionary containing all setup parameters
...@@ -2256,7 +2256,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2256,7 +2256,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
item = getattr(self, item_name) item = getattr(self, item_name)
if item is not None: if item is not None:
item.uninstall(local_configuration) item.uninstall(local_configuration)
# It is better to clear cache because the uninstallation of a # It is better to clear cache because the uninstallation of a
# template deletes many things from the portal. # template deletes many things from the portal.
clearCache() clearCache()
...@@ -2269,14 +2269,14 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2269,14 +2269,14 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
# First, remove obsolete attributes if present. # First, remove obsolete attributes if present.
self._objects = None self._objects = None
for attr in ( '_action_archive', for attr in ( '_action_archive',
'_document_archive', '_document_archive',
'_extension_archive', '_extension_archive',
'_test_archive', '_test_archive',
'_module_archive', '_module_archive',
'_object_archive', '_object_archive',
'_portal_type_archive', '_portal_type_archive',
'_property_archive', '_property_archive',
'_property_sheet_archive'): '_property_sheet_archive'):
if hasattr(self, attr): if hasattr(self, attr):
delattr(self, attr) delattr(self, attr)
...@@ -2286,7 +2286,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2286,7 +2286,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
clean = WorkflowMethod(clean) clean = WorkflowMethod(clean)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getBuildingState') 'getBuildingState')
def getBuildingState(self, id_only=1): def getBuildingState(self, id_only=1):
""" """
...@@ -2297,7 +2297,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2297,7 +2297,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
'business_template_building_workflow') 'business_template_building_workflow')
return wf._getWorkflowStateOf(self, id_only=id_only ) return wf._getWorkflowStateOf(self, id_only=id_only )
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getInstallationState') 'getInstallationState')
def getInstallationState(self, id_only=1): def getInstallationState(self, id_only=1):
""" """
...@@ -2315,11 +2315,11 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2315,11 +2315,11 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
portal_templates = getToolByName(self, 'portal_templates') portal_templates = getToolByName(self, 'portal_templates')
export_string = portal_templates.manage_exportObject( export_string = portal_templates.manage_exportObject(
id=self.getId(), id=self.getId(),
toxml=1, toxml=1,
download=1) download=1)
return export_string return export_string
def _getOrderedList(self, id): def _getOrderedList(self, id):
""" """
We have to set this method because we want an We have to set this method because we want an
...@@ -2389,7 +2389,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2389,7 +2389,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
return self._getOrderedList('template_message_translation') return self._getOrderedList('template_message_translation')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'diff') 'diff')
def diff(self, verbose=0): def diff(self, verbose=0):
""" """
...@@ -2413,7 +2413,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2413,7 +2413,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
if self.getBuildingState() != 'built': if self.getBuildingState() != 'built':
raise TemplateConditionError, 'Business Template must be build before export' raise TemplateConditionError, 'Business Template must be build before export'
if local: if local:
# we export into a folder tree # we export into a folder tree
bta = BusinessTemplateFolder(creation=1, path=path) bta = BusinessTemplateFolder(creation=1, path=path)
...@@ -2421,19 +2421,19 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2421,19 +2421,19 @@ Business Template is a set of definitions, such as skins, portal types and categ
# We export BT into a tarball file # We export BT into a tarball file
bta = BusinessTemplateTarball(creation=1, path=path) bta = BusinessTemplateTarball(creation=1, path=path)
# export bt # export bt
bta.addFolder(path+os.sep+'bt') bta.addFolder(path+os.sep+'bt')
for prop in self.propertyMap(): for prop in self.propertyMap():
type = prop['type'] type = prop['type']
id = prop['id'] id = prop['id']
if id in ('uid', 'rid', 'sid', 'id_group', 'last_id'): if id in ('uid', 'rid', 'sid', 'id_group', 'last_id'):
continue continue
value = self.getProperty(id) value = self.getProperty(id)
if type == 'text' or type == 'string' or type == 'int': if type == 'text' or type == 'string' or type == 'int':
bta.addObject(object=value, name=id, path=path+os.sep+'bt', ext='') bta.addObject(object=value, name=id, path=path+os.sep+'bt', ext='')
elif type == 'lines' or type == 'tokens': elif type == 'lines' or type == 'tokens':
bta.addObject(object=str(os.linesep).join(value), name=id, path=path+os.sep+'bt', ext='') bta.addObject(object=str(os.linesep).join(value), name=id, path=path+os.sep+'bt', ext='')
# Export each part # Export each part
for item_name in self._item_name_list: for item_name in self._item_name_list:
getattr(self, item_name).export(context=self, bta=bta) getattr(self, item_name).export(context=self, bta=bta)
...@@ -2451,7 +2451,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -2451,7 +2451,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
bta = BusinessTemplateFolder(importing=1, file=file, path=root_path) bta = BusinessTemplateFolder(importing=1, file=file, path=root_path)
else: else:
bta = BusinessTemplateTarball(importing=1, file=file) bta = BusinessTemplateTarball(importing=1, file=file)
self._portal_type_item = \ self._portal_type_item = \
PortalTypeTemplateItem(self.getTemplatePortalTypeIdList()) PortalTypeTemplateItem(self.getTemplatePortalTypeIdList())
self._workflow_item = \ self._workflow_item = \
......
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