MCPcopy Create free account
hub / github.com/explorerhq/sql-explorer / _export

Function _export

explorer/views/export.py:8–29  ·  view source on GitHub ↗
(request, query, download=True)

Source from the content-addressed store, hash-verified

6
7
8def _export(request, query, download=True):
9 _fmt = request.GET.get("format", "csv")
10 exporter_class = get_exporter_class(_fmt)
11 query.params = url_get_params(request)
12 delim = request.GET.get("delim")
13 exporter = exporter_class(query)
14 try:
15 output = exporter.get_output(delim=delim)
16 except DatabaseError as e:
17 msg = f"Error executing query {query.title}: {e}"
18 return HttpResponse(
19 msg, status=500
20 )
21
22 response = HttpResponse(
23 output,
24 content_type=exporter.content_type
25 )
26 if download:
27 response["Content-Disposition"] = \
28 f'attachment; filename="{exporter.get_filename()}"'
29 return response

Callers 3

getMethod · 0.90
postMethod · 0.90
getMethod · 0.90

Calls 5

get_exporter_classFunction · 0.90
url_get_paramsFunction · 0.90
get_outputMethod · 0.80
get_filenameMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected