From 5f29f46d6e96f44202a36087ec448e10eda9c8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monge=20Moreno?= Date: Thu, 3 Mar 2016 12:20:58 +0100 Subject: [PATCH] Fix for csv generation encoding --- report_utils/mixins.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/report_utils/mixins.py b/report_utils/mixins.py index bf03dc1..b1b3baa 100644 --- a/report_utils/mixins.py +++ b/report_utils/mixins.py @@ -10,6 +10,7 @@ ReverseManyRelatedObjectsDescriptor as ManyToManyDescriptor ) from django.db.models import Avg, Count, Sum, Max, Min +from django.utils.encoding import smart_str from openpyxl.workbook import Workbook from openpyxl.writer.excel import save_virtual_workbook from openpyxl.cell import get_column_letter @@ -95,7 +96,7 @@ def build_csv_response(self, wb, title="report"): sh = wb.get_active_sheet() c = csv.writer(myfile) for r in sh.rows: - c.writerow([cell.value for cell in r]) + c.writerow([smart_str(cell.value) for cell in r]) response = HttpResponse( myfile.getvalue(), content_type='text/csv') @@ -145,7 +146,7 @@ def list_to_csv_file(self, data, title='report', header=None, widths=None): sh = wb.get_active_sheet() c = csv.writer(myfile) for r in sh.rows: - c.writerow([cell.value for cell in r]) + c.writerow([smart_str(cell.value) for cell in r]) return myfile def list_to_xlsx_response(self, data, title='report', header=None,