From c20eb03a1145eb34f572920a226eff3e26b27b17 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Tue, 24 Mar 2020 11:44:30 +0100 Subject: [PATCH] python3: open report files as binary (#40911) FileReponse wants binary streams, but csv.reader() wants text streams. --- zoo/zoo_nanterre/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zoo/zoo_nanterre/views.py b/zoo/zoo_nanterre/views.py index 0d562e9..4ac02b5 100644 --- a/zoo/zoo_nanterre/views.py +++ b/zoo/zoo_nanterre/views.py @@ -17,6 +17,7 @@ # along with this program. If not, see . import csv +import io import itertools import time @@ -28,7 +29,7 @@ from django.db.transaction import non_atomic_requests, atomic from django.db import connection from django.conf import settings from django.core.cache import cache -from django.utils.timezone import now +from django.utils.timezone import now, six from django.contrib.auth.decorators import permission_required from django.contrib import messages @@ -114,7 +115,10 @@ def synchronize_federations_report(request, job_id, model_admin, *args, **kwargs report = job.action.report if not report: raise Http404('no report') - reader = csv.reader(report) + text_report = report + if six.PY3: + text_report = io.TextIOWrapper(text_report, encoding='utf-8') + reader = csv.reader(text_report) next(reader) actions = [row for row in reader if row[6] != 'KEEP'] context = dict( @@ -145,7 +149,10 @@ def synchronize_federations_apply_report(request, job_id, model_admin, *args, ** report = job.action.apply_report if not report: raise Http404('no report') - reader = csv.reader(report) + text_report = report + if six.PY3: + text_report = io.TextIOWrapper(text_report, encoding='utf-8') + reader = csv.reader(text_report) next(reader) actions = [row for row in reader if row[6] != 'KEEP'] context = dict(