[Erp5-report] r43484 jm - /erp5/trunk/products/ERP5/Document/BusinessTemplate.py

nobody at svn.erp5.org nobody at svn.erp5.org
Sat Feb 19 02:11:57 CET 2011


Author: jm
Date: Sat Feb 19 02:11:56 2011
New Revision: 43484

URL: http://svn.erp5.org?rev=43484&view=rev
Log:
Small refactoring in BusinessTemplate.py

Modified:
    erp5/trunk/products/ERP5/Document/BusinessTemplate.py

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=43484&r1=43483&r2=43484&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Sat Feb 19 02:11:56 2011
@@ -812,16 +812,19 @@ class ObjectTemplateItem(BaseTemplateIte
       outfile.close()
       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):
     # import xml file
     if not file_name.endswith('.xml'):
       LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
       return
-    obj = self
-    connection = None
-    while connection is None:
-      obj=obj.aq_parent
-      connection=obj._p_jar
+    connection = self.getConnection(self.aq_parent)
     __traceback_info__ = 'Importing %s' % file_name
     if hasattr(cache_database, 'db') and isinstance(file_obj, file):
       obj = connection.importFile(self._compileXML(file_obj))
@@ -1126,11 +1129,7 @@ class ObjectTemplateItem(BaseTemplateIte
           # import sub objects if there is
           if subobjects_dict:
             # get a jar
-            connection = obj._p_jar
-            o = obj
-            while connection is None:
-              o = o.aq_parent
-              connection = o._p_jar
+            connection = self.getConnection(obj)
             # import subobjects
             for subobject_id, subobject_data in subobjects_dict.iteritems():
               try:
@@ -2696,11 +2695,7 @@ class CatalogMethodTemplateItem(ObjectTe
           self._method_properties.setdefault(id, PersistentMapping())[key] = 1
     elif file_name.endswith('.xml'):
       # just import xml object
-      obj = self
-      connection = None
-      while connection is None:
-        obj=obj.aq_parent
-        connection=obj._p_jar
+      connection = self.getConnection(self.aq_parent)
       obj = connection.importFile(file, customImporters=customImporters)
       self.removeProperties(obj, 0)
       self._objects[file_name[:-4]] = obj



More information about the Erp5-report mailing list