diff options
| author | Xavier Morel <xmo@odoo.com> | 2017-05-12 12:23:31 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2017-08-20 23:25:54 +0200 |
| commit | be7c5aefdf10ad424f2f3c442e135fb81af3d419 (patch) | |
| tree | 45c7428ee29a5be8e48c72eb2fa1315067120705 /addons/web/controllers | |
| parent | 0797cfd355df531d801e9d152898ae9046403f2a (diff) | |
[FIX] P3: CSV reading & writing
Diffstat (limited to 'addons/web/controllers')
| -rw-r--r-- | addons/web/controllers/main.py | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 9ac7b7a2fd8..ebe9e8aa16d 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -3,7 +3,6 @@ import babel.messages.pofile import base64 -import csv import datetime import functools import glob @@ -1389,31 +1388,21 @@ class CSVExport(ExportFormat, http.Controller): def from_data(self, fields, rows): fp = io.BytesIO() - writer = csv.writer(fp, quoting=csv.QUOTE_ALL) + writer = pycompat.csv_writer(fp, quoting=1) - writer.writerow([name.encode('utf-8') for name in fields]) + writer.writerow(fields) for data in rows: row = [] for d in data: - if type(d) != str and isinstance(d, pycompat.string_types): - try: - d = d.encode('utf-8') - except UnicodeError: - pass - if d is False: d = None - # Spreadsheet apps tend to detect formulas on leading =, + and - - if type(d) is str and d.startswith(('=', '-', '+')): + if isinstance(d, pycompat.string_types) and d.startswith(('=', '-', '+')): d = "'" + d - row.append(d) + row.append(pycompat.to_text(d)) writer.writerow(row) - fp.seek(0) - data = fp.read() - fp.close() - return data + return fp.getvalue() class ExcelExport(ExportFormat, http.Controller): # Excel needs raw data to correctly handle numbers and date values |
