From 335952c033df491c936386b094f840aeffe739ec Mon Sep 17 00:00:00 2001 From: JulieRossi Date: Mon, 18 Sep 2017 18:51:13 +0200 Subject: [PATCH] Create CsvResponse to manage csv exports encoding (#3484) --- superset/views/base.py | 7 +++++++ superset/views/core.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/superset/views/base.py b/superset/views/base.py index 02aaf8daef3b5..73627d0463fcf 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -336,3 +336,10 @@ def apply(self, query, func): # noqa perms = self.get_view_menus('datasource_access') # TODO(bogdan): add `schema_access` support here return query.filter(self.model.perm.in_(perms)) + + +class CsvResponse(Response): + """ + Override Response to take into account csv encoding from config.py + """ + charset = conf.get('CSV_EXPORT').get('encoding', 'utf-8') diff --git a/superset/views/core.py b/superset/views/core.py index 72d2cf6cafbb5..faa61ad4374a4 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -43,8 +43,8 @@ from .base import ( api, SupersetModelView, BaseSupersetView, DeleteMixin, - SupersetFilter, get_user_roles, json_error_response, get_error_msg -) + SupersetFilter, get_user_roles, json_error_response, get_error_msg, + CsvResponse) config = app.config stats_logger = config.get('STATS_LOGGER') @@ -959,7 +959,7 @@ def explore_json(self, datasource_type, datasource_id): return json_error_response(DATASOURCE_ACCESS_ERR, status=404) if request.args.get("csv") == "true": - return Response( + return CsvResponse( viz_obj.get_csv(), status=200, headers=generate_download_headers("csv"),