summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-11-23 15:21:57 +0100
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2017-11-27 11:11:48 +0100
commitb46830858f44b83b185df4f83e20aad69b48d330 (patch)
tree32f6ccdb657f4bccf1721b065a3fdc0f0f76d380 /addons/web/controllers
parent63623cbdcbdbca558418511474069fe390d4aa90 (diff)
[FIX] web: excel export of binary fields
* In Python 3 xlwt apparently does not support writing bytes values -> try to decode assuming the value may be base64-encoded, this is more or less the behaviour for CSV exports. This will most likely not allow the export anyway as Excel cells are limited to 32k data characters, which accounting for base64 expansion means ~24k worth of data, but that is a pre-existing issue. * Also removed support for way outdated browsers from content_disposition: the Safari case is for Safari 5 (circa 2012) but versioning apparently changed since then and modern Safari report their "external" version number rather than the webkit version number => the current Safari reports version 11, and gets routed to the "does not support unicode file names", which is further bugged in Python 3 as it %s's bytes, leading to a resulting filename of e.g. `b'res.partner.csv'.csv` (with the prefix and quotes). * The IE case is for IE8, which has long been unsupported by the web client.
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 82329378975..438270ecfe6 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1390,7 +1390,6 @@ class ExportFormat(object):
else:
columns_headers = [val['label'].strip() for val in fields]
-
return request.make_response(self.from_data(columns_headers, import_data),
headers=[('Content-Disposition',
content_disposition(self.filename(model))),
@@ -1463,8 +1462,19 @@ class ExcelExport(ExportFormat, http.Controller):
for row_index, row in enumerate(rows):
for cell_index, cell_value in enumerate(row):
cell_style = base_style
+
+ if isinstance(cell_value, bytes) and not isinstance(cell_value, pycompat.string_types):
+ # because xls uses raw export, we can get a bytes object
+ # here. xlwt does not support bytes values in Python 3 ->
+ # assume this is base64 and decode to a string, if this
+ # fails note that you can't export
+ try:
+ cell_value = pycompat.to_text(cell_value)
+ except UnicodeDecodeError:
+ raise UserError(_("Binary fields can not be exported to Excel unless their content is base64-encoded. That does not seem to be the case for %s.") % fields[cell_index])
+
if isinstance(cell_value, pycompat.string_types):
- cell_value = re.sub("\r", " ", cell_value)
+ cell_value = re.sub("\r", " ", pycompat.to_text(cell_value))
elif isinstance(cell_value, datetime.datetime):
cell_style = datetime_style
elif isinstance(cell_value, datetime.date):