mirror of
https://github.com/apache/superset.git
synced 2026-06-07 16:49:17 +00:00
Csv download improvements
* name + extension for generated csv and json files * write csv index where data is meaningful
This commit is contained in:
committed by
Maxime Beauchemin
parent
345727635e
commit
65e72d0d07
@@ -36,6 +36,15 @@ def validate_json(form, field): # noqa
|
||||
raise ValidationError("json isn't valid")
|
||||
|
||||
|
||||
def generate_download_headers(extension):
|
||||
filename = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
content_disp = "attachment; filename={}.{}".format(filename, extension)
|
||||
headers = {
|
||||
"Content-Disposition": content_disp,
|
||||
}
|
||||
return headers
|
||||
|
||||
|
||||
class DeleteMixin(object):
|
||||
@action(
|
||||
"muldelete", "Delete", "Delete all Really?", "fa-trash", single=False)
|
||||
@@ -477,6 +486,7 @@ class Caravel(BaseView):
|
||||
resp = Response(
|
||||
payload,
|
||||
status=status,
|
||||
headers=generate_download_headers("json"),
|
||||
mimetype="application/json")
|
||||
return resp
|
||||
elif request.args.get("csv") == "true":
|
||||
@@ -485,6 +495,7 @@ class Caravel(BaseView):
|
||||
return Response(
|
||||
payload,
|
||||
status=status,
|
||||
headers=generate_download_headers("csv"),
|
||||
mimetype="application/csv")
|
||||
else:
|
||||
if request.args.get("standalone") == "true":
|
||||
|
||||
@@ -257,7 +257,8 @@ class BaseViz(object):
|
||||
|
||||
def get_csv(self):
|
||||
df = self.get_df()
|
||||
return df.to_csv(index=False)
|
||||
include_index = not isinstance(df.index, pd.RangeIndex)
|
||||
return df.to_csv(index=include_index)
|
||||
|
||||
def get_data(self):
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user