From f470dacd3ee1f93b52bdb54d47bd4cbafd8a3840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 18 May 2021 22:08:59 +0200 Subject: [PATCH] Support Binary field in CSV import/export issue10350 review346101002 --- CHANGELOG | 2 ++ tryton/gui/window/win_export.py | 3 +++ tryton/gui/window/win_import.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index be3d76ff0f..a9f335b0a5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Support Binary field in CSV import/export + Version 6.0.0 - 2021-05-03 * Bug fixes (see mercurial logs for details) * Support printing zip archive diff --git a/tryton/gui/window/win_export.py b/tryton/gui/window/win_export.py index 0a8775bfee..275a9adac8 100644 --- a/tryton/gui/window/win_export.py +++ b/tryton/gui/window/win_export.py @@ -1,5 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +import base64 import csv import datetime import os @@ -426,6 +427,8 @@ class WinExport(WinCSV): val = int(val) if i == 0 and indent and isinstance(val, str): val = ' ' * indent + val + if isinstance(val, bytes): + val = base64.b64encode(val).decode('utf-8') row.append(val) return row diff --git a/tryton/gui/window/win_import.py b/tryton/gui/window/win_import.py index 409f84d0e6..5bfe04dacf 100644 --- a/tryton/gui/window/win_import.py +++ b/tryton/gui/window/win_import.py @@ -1,5 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +import base64 import csv import gettext import locale @@ -208,6 +209,8 @@ class WinImport(WinCSV): val = Decimal(locale.delocalize(val)) elif type_ in ['date', 'datetime']: val = date_parse(val, common.date_format()) + elif type_ == 'binary': + val = base64.b64decode(val) row.append(val) data.append(row) try: