Use utf8 encoding when downloading results as CSV

This commit is contained in:
Lance Edgar 2020-08-21 18:35:27 -05:00
parent 1b7612ffb0
commit 43472c7eb6

View file

@ -27,6 +27,7 @@ Model Master View
from __future__ import unicode_literals, absolute_import
import os
import csv
import datetime
import tempfile
import logging
@ -2720,8 +2721,13 @@ class MasterView(View):
results = results.with_session(session).all()
fields = self.get_csv_fields()
csv_file = open(path, 'wt')
writer = UnicodeDictWriter(csv_file, fields)
if six.PY2:
csv_file = open(path, 'wb')
writer = UnicodeDictWriter(csv_file, fields, encoding='utf_8')
else: # PY3
csv_file = open(path, 'wt', encoding='utf_8')
writer = csv.DictWriter(csv_file, fields)
writer.writeheader()
def write(obj, i):