Commit 74c171cd authored by Julien Muchembled's avatar Julien Muchembled

Small refactoring in BusinessTemplate.py

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43484 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ef922984
...@@ -812,16 +812,19 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -812,16 +812,19 @@ class ObjectTemplateItem(BaseTemplateItem):
outfile.close() outfile.close()
raise raise
def getConnection(self, obj):
while True:
connection = obj._p_jar
if connection is not None:
return connection
obj = obj.aq_parent
def _importFile(self, file_name, file_obj): def _importFile(self, file_name, file_obj):
# import xml file # import xml file
if not file_name.endswith('.xml'): if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, )) LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return return
obj = self connection = self.getConnection(self.aq_parent)
connection = None
while connection is None:
obj=obj.aq_parent
connection=obj._p_jar
__traceback_info__ = 'Importing %s' % file_name __traceback_info__ = 'Importing %s' % file_name
if hasattr(cache_database, 'db') and isinstance(file_obj, file): if hasattr(cache_database, 'db') and isinstance(file_obj, file):
obj = connection.importFile(self._compileXML(file_obj)) obj = connection.importFile(self._compileXML(file_obj))
...@@ -1126,11 +1129,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1126,11 +1129,7 @@ class ObjectTemplateItem(BaseTemplateItem):
# import sub objects if there is # import sub objects if there is
if subobjects_dict: if subobjects_dict:
# get a jar # get a jar
connection = obj._p_jar connection = self.getConnection(obj)
o = obj
while connection is None:
o = o.aq_parent
connection = o._p_jar
# import subobjects # import subobjects
for subobject_id, subobject_data in subobjects_dict.iteritems(): for subobject_id, subobject_data in subobjects_dict.iteritems():
try: try:
...@@ -2696,11 +2695,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -2696,11 +2695,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
self._method_properties.setdefault(id, PersistentMapping())[key] = 1 self._method_properties.setdefault(id, PersistentMapping())[key] = 1
elif file_name.endswith('.xml'): elif file_name.endswith('.xml'):
# just import xml object # just import xml object
obj = self connection = self.getConnection(self.aq_parent)
connection = None
while connection is None:
obj=obj.aq_parent
connection=obj._p_jar
obj = connection.importFile(file, customImporters=customImporters) obj = connection.importFile(file, customImporters=customImporters)
self.removeProperties(obj, 0) self.removeProperties(obj, 0)
self._objects[file_name[:-4]] = obj self._objects[file_name[:-4]] = obj
......
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