From f578a5c8e8498feb7484ea75b79125ec9ccfe58e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Fri, 18 Nov 2005 16:20:21 +0000
Subject: [PATCH] Fix bug in xml format for CatalogMethod

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4360 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py | 38 +++++++++++++++++------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index 48ec790412..c5f973cc9b 100755
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -1014,10 +1014,17 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
             XMLExportImport.exportXML(object._p_jar, object._p_oid, object_io)
             bta.addObject(object = object_io.getvalue(), name=id+'.filter_instance', path=path)
           else:
-            xml_data += os.linesep+' <method>'
-            xml_data += os.linesep+'  <key>%s</key>' %(method)
-            xml_data += os.linesep+'  <value>%s</value>' %(str(value))
-            xml_data += os.linesep+' </method>'
+            if type(value) in (type(''), type(u'')):
+              xml_data += os.linesep+' <method type="">'
+              xml_data += os.linesep+'  <key>%s</key>' %(method)
+              xml_data += os.linesep+'  <value>%s</value>' %(str(value))
+              xml_data += os.linesep+' </method>'
+            elif type(value) in (type(()), type([])):
+              xml_data += os.linesep+' <method type="tuple">'
+              xml_data += os.linesep+'  <key>%s</key>' %(method)
+              for item in value:
+                xml_data += os.linesep+'  <value>%s</value>' %(str(item))
+              xml_data += os.linesep+' </method>'
       xml_data += os.linesep+'</catalog_method>'
       f.write(str(xml_data))
       f.close()
@@ -1165,13 +1172,24 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
       xml = parse(file)
       method_list = xml.getElementsByTagName('method')
       for method in method_list:
-        key = method.getElementsByTagName('key')[0].childNodes[0].data
-        value = method.getElementsByTagName('value')[0].childNodes[0].data
-        key = str(key)
-        if key in catalog_method_list:
-          value = int(value)
+        type = method.getAttribute('type')
+        if type == "":
+          key = method.getElementsByTagName('key')[0].childNodes[0].data
+          value = method.getElementsByTagName('value')[0].childNodes[0].data
+          key = str(key)
+          if key in catalog_method_list:
+            value = int(value)
+          else:
+            value = str(value)
+        elif type == "tuple":
+          value = []
+          key = method.getElementsByTagName('key')[0].childNodes[0].data
+          value_list = method.getElementsByTagName('value')
+          for item in value_list:
+            value.append(item.childNodes[0].data)
         else:
-          value = str(value)
+          LOG('BusinessTemplate import CatalogMethod, type unknown', 0, type)
+          continue
         dict = getattr(self, key)
         dict[id] = value
     elif '.filter_instance' in file_name:
-- 
2.30.9