[dashboard] Also support downloading facet result in csv and xls
@@ -273,19 +273,22 @@ def download(request):
file_format = 'csv' if 'csv' == request.POST.get('type') else 'xls' if 'xls' == request.POST.get('type') else 'json'
facet = json.loads(request.POST.get('facet', '{}'))
- response = search(request)
+ json_response = search(request)
+ response = json.loads(json_response.content)
- if file_format == 'json':
if facet:
- docs = json.loads(response.content)['normalized_facets'][0]['docs']
+ response['response']['docs'] = response['normalized_facets'][0]['docs']
+ collection = facet
else:
- docs = json.loads(response.content)['response']['docs']
+ collection = json.loads(request.POST.get('collection', '{}'))
+
+ if file_format == 'json':
+ docs = response['response']['docs']
resp = JsonResponse(docs, safe=False)
resp['Content-Disposition'] = 'attachment; filename=%s.%s' % ('query_result', file_format)
return resp
else:
- collection = json.loads(request.POST.get('collection', '{}'))
- return export_download(json.loads(response.content), file_format, collection)
+ return export_download(response, file_format, collection)
except Exception, e:
raise PopupException(_("Could not download search results: %s") % e)
