Create CsvResponse to manage csv exports encoding (#3484)

This commit is contained in:
JulieRossi 2017-09-18 18:51:13 +02:00 committed by Maxime Beauchemin
parent e66f68d36c
commit a26e65f418
2 changed files with 10 additions and 3 deletions

View File

@ -336,3 +336,10 @@ class DatasourceFilter(SupersetFilter):
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')

View File

@ -43,8 +43,8 @@ from superset.sql_parse import SupersetQuery
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 @@ class Superset(BaseSupersetView):
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"),