Fix encoding bug for python 3, when downloading CSV results

This commit is contained in:
Lance Edgar 2018-02-14 15:27:55 -06:00
parent 79634d402e
commit 135e98cde1

View file

@ -1935,11 +1935,16 @@ class MasterView(View):
for obj in results:
writer.writerow(self.get_csv_row(obj, fields))
response = self.request.response
if six.PY3:
response.text = data.getvalue()
response.content_type = 'text/csv'
response.content_disposition = 'attachment; filename={}.csv'.format(self.get_grid_key())
else:
response.body = data.getvalue()
data.close()
response.content_length = len(response.body)
response.content_type = b'text/csv'
response.content_disposition = b'attachment; filename={}.csv'.format(self.get_grid_key())
data.close()
response.content_length = len(response.body)
return response
def results_xlsx(self):