浏览代码

HUE-7220 [dashboard] Also support downloading facet result in csv and xls

Romain Rigaux 8 年之前
父节点
当前提交
47cb638
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      desktop/libs/dashboard/src/dashboard/api.py

+ 10 - 7
desktop/libs/dashboard/src/dashboard/api.py

@@ -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 facet:
+      response['response']['docs'] = response['normalized_facets'][0]['docs']
+      collection = facet
+    else:
+      collection = json.loads(request.POST.get('collection', '{}'))
 
     if file_format == 'json':
-      if facet:
-        docs = json.loads(response.content)['normalized_facets'][0]['docs']
-      else:
-        docs = json.loads(response.content)['response']['docs']
+      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)