From 135e98cde119c305200af96173ee4a38039ec3dc Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 14 Feb 2018 15:27:55 -0600 Subject: [PATCH] Fix encoding bug for python 3, when downloading CSV results --- tailbone/views/master.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 5a36bcb9..68ae7615 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -1935,11 +1935,16 @@ class MasterView(View): for obj in results: writer.writerow(self.get_csv_row(obj, fields)) response = self.request.response - response.body = data.getvalue() + 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() + 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) - response.content_type = b'text/csv' - response.content_disposition = b'attachment; filename={}.csv'.format(self.get_grid_key()) return response def results_xlsx(self):