فهرست منبع

[search] Download first 1000 rows of a query

Currently only download the current page.
We can see later for enabling more rows to be downloaded.
Romain Rigaux 11 سال پیش
والد
کامیت
bca90eb
3فایلهای تغییر یافته به همراه17 افزوده شده و 7 حذف شده
  1. 5 4
      apps/search/src/search/templates/search.mako
  2. 2 1
      apps/search/src/search/views.py
  3. 10 2
      desktop/libs/libsolr/src/libsolr/api.py

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

@@ -687,14 +687,15 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
     </i>
   </a>
 
-  <!-- ko if: $data.response.numFound > 0 && $data.response.numFound <= 1000 -->
+  <!-- ko if: $data.response.numFound > 0 -->
   <span class="pull-right">
     <form method="POST" action="${ url('search:download') }">
       <input type="hidden" name="collection" data-bind="value: ko.mapping.toJSON($root.collection)"/>
       <input type="hidden" name="query" data-bind="value: ko.mapping.toJSON($root.query)"/>
-      <button class="btn" type="submit" name="json" title="${ _('Download as JSON') }"><i class="hfo hfo-file-json"></i></button>
-      <button class="btn" type="submit" name="csv" title="${ _('Download as CSV') }"><i class="hfo hfo-file-csv"></i></button>
-      <button class="btn" type="submit" name="xls" title="${ _('Download as Excel') }"><i class="hfo hfo-file-xls"></i></button>
+      <input type="hidden" name="download">
+      <button class="btn" type="submit" name="json" title="${ _('Download first rows as JSON') }"><i class="hfo hfo-file-json"></i></button>
+      <button class="btn" type="submit" name="csv" title="${ _('Download first rows as CSV') }"><i class="hfo hfo-file-csv"></i></button>
+      <button class="btn" type="submit" name="xls" title="${ _('Download first rows as XLS') }"><i class="hfo hfo-file-xls"></i></button>
     </form>
   </span>
   <!-- /ko -->

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

@@ -123,6 +123,7 @@ def search(request):
 
   collection = json.loads(request.POST.get('collection', '{}'))
   query = json.loads(request.POST.get('query', '{}'))
+  query['download'] = 'download' in request.POST
   # todo: remove the selected histo facet if multiq
 
   if collection['id']:
@@ -157,7 +158,7 @@ def save(request):
   collection = json.loads(request.POST.get('collection', '{}')) # TODO perms
   layout = json.loads(request.POST.get('layout', '{}'))
 
-  collection['template']['extracode'] = escape(collection['template']['extracode']) # Escape HTML
+  collection['template']['extracode'] = escape(collection['template']['extracode'])
 
   if collection:
     if collection['id']:

+ 10 - 2
desktop/libs/libsolr/src/libsolr/api.py

@@ -61,8 +61,16 @@ class SolrApi(object):
     solr_query = {}
 
     solr_query['collection'] = collection['name']
-    solr_query['rows'] = min(int(collection['template']['rows'] or 10), 1000)
-    solr_query['start'] = min(int(query['start']), 10000)
+
+    if query['download']:
+      solr_query['rows'] = 1000
+      solr_query['start'] = 0
+    else:
+      solr_query['rows'] = int(collection['template']['rows'] or 10)
+      solr_query['start'] = int(query['start'])
+
+    solr_query['rows'] = min(solr_query['rows'], 1000)
+    solr_query['start'] = min(solr_query['start'], 10000)
 
     q_template = '(%s)' if len(query['qs']) >= 2 else '%s'