Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -477,6 +486,7 @@ def explore(self, datasource_type, datasource_id):
resp = Response(
payload,
status=status,
headers=generate_download_headers("json"),
mimetype="application/json")
return resp
elif request.args.get("csv") == "true":
Expand All @@ -485,6 +495,7 @@ def explore(self, datasource_type, datasource_id):
return Response(
payload,
status=status,
headers=generate_download_headers("csv"),
mimetype="application/csv")
else:
if request.args.get("standalone") == "true":
Expand Down
3 changes: 2 additions & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def get_json(self):

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 []
Expand Down