From 8c52fe073a975ba1a5b613a72ff12d498f7c629d Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Wed, 22 Dec 2010 10:30:59 +0000 Subject: [PATCH] quote non-str types like list, dict etc. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41650 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../erp5_csv_style/Listbox_exportCsv.xml | 37 ++++++++----------- bt5/erp5_csv_style/bt/revision | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/bt5/erp5_csv_style/SkinTemplateItem/portal_skins/erp5_csv_style/Listbox_exportCsv.xml b/bt5/erp5_csv_style/SkinTemplateItem/portal_skins/erp5_csv_style/Listbox_exportCsv.xml index 737e017e61..383104c532 100644 --- a/bt5/erp5_csv_style/SkinTemplateItem/portal_skins/erp5_csv_style/Listbox_exportCsv.xml +++ b/bt5/erp5_csv_style/SkinTemplateItem/portal_skins/erp5_csv_style/Listbox_exportCsv.xml @@ -60,6 +60,18 @@ translate = context.portal_url.getPortalObject().Localizer.erp5_ui.gettext\n \n listboxline_list = context.get_value(\'default\', render_format=\'list\', REQUEST=request)\n \n +def encode(value):\n + if isinstance(value, bool):\n + return \'"%s"\' % value\n + if isinstance(value, (int, long, float)):\n + return str(value)\n + else:\n + if isinstance(value, str):\n + value = value.decode(\'utf-8\')\n + else:\n + value = str(value)\n + return \'"%s"\' % value.replace(\'"\', \'""\')\n +\n for listboxline in listboxline_list:\n if listboxline.isTitleLine():\n line_result = \'\'\n @@ -74,22 +86,11 @@ for listboxline in listboxline_list:\n column_property = column_item[1]\n \n if column_id is not None:\n - if same_type(column_id,\'\'):\n - column_id = column_id.replace(\'"\',\'""\')\n - line_result += \'"%s"\' % column_id.decode(\'utf-8\')\n - else:\n - line_result += str(column_id)\n -\n + line_result += encode(column_id)\n line_result += str(\',\')\n \n if column_property is not None:\n - if same_type(column_property,\'\'):\n - column_property = translate(column_property.decode(\'utf-8\'))\n - column_property = column_property.replace(\'"\',\'""\')\n - line_result2 += \'"%s"\' % column_property\n - else:\n - line_result2 += str(column_property)\n -\n + line_result2 += encode(column_property)\n line_result2 += str(\',\')\n \n if len(line_result) > 1:\n @@ -114,15 +115,7 @@ for listboxline in listboxline_list:\n for column_property in listboxline.getColumnPropertyList():\n \n if column_property is not None:\n - if same_type(column_property,\'\'):\n - column_property = column_property.replace(\'"\',\'""\')\n - line_result += \'"%s"\' % column_property.decode(\'utf-8\')\n - elif same_type(column_property,1.0):\n - column_property = str(column_property).replace(\'.\',\',\')\n - line_result += \'"%s"\' % column_property\n - else:\n - line_result += str(column_property)\n -\n + line_result += encode(column_property)\n line_result += str(\',\')\n \n if len(line_result) > 1:\n diff --git a/bt5/erp5_csv_style/bt/revision b/bt5/erp5_csv_style/bt/revision index 3f10ffe7a4..19c7bdba7b 100644 --- a/bt5/erp5_csv_style/bt/revision +++ b/bt5/erp5_csv_style/bt/revision @@ -1 +1 @@ -15 \ No newline at end of file +16 \ No newline at end of file -- 2.30.9