Skip to content

Commit

Permalink
Create CsvResponse to manage csv exports encoding (apache#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieRossi authored and michellethomas committed May 23, 2018
1 parent 025974e commit 335952c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
6 changes: 3 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 335952c

Please sign in to comment.