superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: config: allow changing default options for writting csv (#3441)
Date Fri, 15 Sep 2017 00:40:17 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b90d8e3  config: allow changing default options for writting csv (#3441)
b90d8e3 is described below

commit b90d8e32f1b26e478e7d81de48d7766c2ff72362
Author: JulieRossi <julierossi06@gmail.com>
AuthorDate: Fri Sep 15 02:40:15 2017 +0200

    config: allow changing default options for writting csv (#3441)
---
 superset/config.py     | 5 +++++
 superset/views/core.py | 4 ++--
 superset/viz.py        | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/superset/config.py b/superset/config.py
index d7125a4..0cbf7d3 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -181,6 +181,11 @@ TABLE_NAMES_CACHE_CONFIG = {'CACHE_TYPE': 'null'}
 ENABLE_CORS = False
 CORS_OPTIONS = {}
 
+# CSV Options: key/value pairs that will be passed as argument to DataFrame.to_csv method
+# note: index option should not be overridden
+CSV_EXPORT = {
+    'encoding': 'utf-8',
+}
 
 # ---------------------------------------------------
 # List of viz_types not allowed in your environment
diff --git a/superset/views/core.py b/superset/views/core.py
index 68e8202..72d2cf6 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2126,13 +2126,13 @@ class Superset(BaseSupersetView):
             columns = [c['name'] for c in obj['columns']]
             df = pd.DataFrame.from_records(obj['data'], columns=columns)
             logging.info("Using pandas to convert to CSV")
-            csv = df.to_csv(index=False, encoding='utf-8')
+            csv = df.to_csv(index=False, **config.get('CSV_EXPORT'))
         else:
             logging.info("Running a query to turn into CSV")
             sql = query.select_sql or query.executed_sql
             df = query.database.get_df(sql, query.schema)
             # TODO(bkyryliuk): add compression=gzip for big files.
-            csv = df.to_csv(index=False, encoding='utf-8')
+            csv = df.to_csv(index=False, **config.get('CSV_EXPORT'))
         response = Response(csv, mimetype='text/csv')
         response.headers['Content-Disposition'] = (
             'attachment; filename={}.csv'.format(query.name))
diff --git a/superset/viz.py b/superset/viz.py
index 0e952b3..7226d2e 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -310,7 +310,7 @@ class BaseViz(object):
     def get_csv(self):
         df = self.get_df()
         include_index = not isinstance(df.index, pd.RangeIndex)
-        return df.to_csv(index=include_index, encoding="utf-8")
+        return df.to_csv(index=include_index, **config.get('CSV_EXPORT'))
 
     def get_data(self, df):
         return []

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message