python3: open report files as binary (#40911)

FileReponse wants binary streams, but csv.reader() wants text streams.
This commit is contained in:
Nicolas Roche 2020-03-24 11:44:30 +01:00
parent ec91ea59b1
commit c20eb03a11
1 changed files with 10 additions and 3 deletions

View File

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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(