Browse Source

HUE-3228 [search] Fix import that was not properly renamed

Romain Rigaux 8 years ago
parent
commit
36f1637c58

+ 20 - 1
apps/search/src/search/api.py

@@ -29,10 +29,11 @@ from libsolr.api import SolrApi
 
 from search.api_engines import get_engine
 from search.conf import SOLR_URL
+from search.data_export import download as export_download
 from search.decorators import allow_viewer_only
 from search.facet_builder import _guess_gap, _zoom_range_facet, _new_range_facet
 from search.models import Collection2, augment_solr_response, pairwise2, augment_solr_exception
-from search.search_controller import SearchController, can_edit_index
+from search.search_controller import can_edit_index
 
 
 LOG = logging.getLogger(__name__)
@@ -265,6 +266,24 @@ def get_terms(request):
   return JsonResponse(result)
 
 
+@allow_viewer_only
+def download(request):
+  try:
+    file_format = 'csv' if 'csv' == request.POST.get('type') else 'xls' if 'xls' == request.POST.get('type') else 'json'
+    response = search(request)
+
+    if file_format == 'json':
+      docs = json.loads(response.content)['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)
+  except Exception, e:
+    raise PopupException(_("Could not download search results: %s") % e)
+
+
 @allow_viewer_only
 def get_timeline(request):
   result = {'status': -1, 'message': 'Error'}

+ 5 - 5
apps/search/src/search/templates/common_search.mako

@@ -1492,11 +1492,11 @@ ${ dashboard.layout_skeleton() }
                   <i class="hfo hfo-file-json"></i> JSON
                 </a>
               </li>
-              <li>
-                <a class="inactive-action download" href="javascript:void(0)" data-bind="click: function(widget, event){ var $f = $(event.currentTarget).parents('form'); $f.find('[name=\'type\']').val('json'); $f.submit()}" title="${ _('Download first rows as JSON') }">
-                  <i class="fa fa-w fa-save"></i> ${_('Save')}
-                </a>
-              </li>
+              ##<li>
+                ##<a class="inactive-action download" href="javascript:void(0)" data-bind="click: function(widget, event){ var $f = $(event.currentTarget).parents('form'); $f.find('[name=\'type\']').val('json'); $f.submit()}" title="${ _('Export results to a dataset') }">
+                ##  <i class="fa fa-w fa-save"></i> ${_('Export')}
+                ##</a>
+              ##</li>
             </ul>
           </div>
         </form>

+ 1 - 1
apps/search/src/search/tests.py

@@ -28,7 +28,7 @@ from desktop.lib.test_utils import grant_access
 from desktop.lib.rest import resource
 from desktop.models import Document2
 
-from search.api import _round_number_range
+from search.facet_builder import _round_number_range
 from search.models import Collection2
 from search.search_controller import SearchController
 

+ 1 - 1
apps/search/src/search/urls.py

@@ -26,7 +26,6 @@ urlpatterns = patterns('search.views',
   url(r'^embeddable/new_search', 'new_search_embeddable', name='new_search_embeddable'),
   url(r'^browse/(?P<name>.+)', 'browse', name='browse'),
   url(r'^browse_m/(?P<name>.+)', 'browse_m', name='browse_m'),
-  url(r'^download$', 'download', name='download'),
 
   # Admin
   url(r'^admin/collections$', 'admin_collections', name='admin_collections'),
@@ -46,6 +45,7 @@ urlpatterns += patterns('search.api',
   url(r'^get_document$', 'get_document', name='get_document'),
   url(r'^update_document$', 'update_document', name='update_document'),
   url(r'^get_range_facet$', 'get_range_facet', name='get_range_facet'),
+  url(r'^download$', 'download', name='download'),
   url(r'^get_timeline$', 'get_timeline', name='get_timeline'),
   url(r'^get_collection$', 'get_collection', name='get_collection'),
   url(r'^get_collections$', 'get_collections', name='get_collections'),

+ 1 - 20
apps/search/src/search/views.py

@@ -30,8 +30,7 @@ from indexer.management.commands import indexer_setup
 
 from search.api_engines import get_engine
 from search.conf import LATEST
-from search.data_export import download as export_download
-from search.decorators import allow_owner_only, allow_viewer_only
+from search.decorators import allow_owner_only
 from search.management.commands import search_setup
 from search.models import Collection2, get_engines
 from search.search_controller import SearchController, can_edit_index
@@ -199,24 +198,6 @@ def save(request):
   return JsonResponse(response)
 
 
-@allow_viewer_only
-def download(request):
-  try:
-    file_format = 'csv' if 'csv' == request.POST.get('type') else 'xls' if 'xls' == request.POST.get('type') else 'json'
-    response = search(request)
-
-    if file_format == 'json':
-      docs = json.loads(response.content)['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)
-  except Exception, e:
-    raise PopupException(_("Could not download search results: %s") % e)
-
-
 def no_collections(request):
   return render('no_collections.mako', request, {})