[extensions-web] extensions: Allow non-paginated queries



commit 437db054975662ac332d3d9351900e29ba55fb84
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jun 13 22:14:03 2012 -0400

    extensions: Allow non-paginated queries
    
    A request from John Stowers.

 sweettooth/extensions/search.py |    2 +-
 sweettooth/extensions/views.py  |   26 +++++++++++++++++++-------
 2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/sweettooth/extensions/search.py b/sweettooth/extensions/search.py
index 9d01ce5..253903a 100644
--- a/sweettooth/extensions/search.py
+++ b/sweettooth/extensions/search.py
@@ -60,4 +60,4 @@ def enquire(querystring):
     enquire = xapian.Enquire(db)
     enquire.set_query(qp.parse_query(querystring))
 
-    return enquire
+    return db, enquire
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 36d92af..2026098 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -115,7 +115,7 @@ def shell_update(request):
 
     return operations
 
-def ajax_query_params_query(request, n_per_page=10):
+def ajax_query_params_query(request, n_per_page):
     version_qs = models.ExtensionVersion.objects.visible()
 
     version_strings = request.GET.getlist('shell_version')
@@ -145,6 +145,9 @@ def ajax_query_params_query(request, n_per_page=10):
     order = request.GET.get('order', default_order)
     queryset.query.standard_ordering = (order == 'asc')
 
+    if n_per_page == -1:
+        return queryset, 1
+
     # Paginate the query
     paginator = Paginator(queryset, n_per_page)
     page = request.GET.get('page', 1)
@@ -160,10 +163,10 @@ def ajax_query_params_query(request, n_per_page=10):
 
     return page_obj.object_list, paginator.num_pages
 
-def ajax_query_search_query(request, n_per_page=10):
+def ajax_query_search_query(request, n_per_page):
     querystring = request.GET.get('search', '')
 
-    enquire = search.enquire(querystring)
+    database, enquire = search.enquire(querystring)
 
     page = request.GET.get('page', 1)
     try:
@@ -171,10 +174,14 @@ def ajax_query_search_query(request, n_per_page=10):
     except ValueError:
         raise Http404()
 
-    mset = enquire.get_mset(offset, n_per_page)
-    pks = [match.document.get_data() for match in mset]
+    if n_per_page == -1:
+        mset = enquire.get_mset(offset, database.get_doccount())
+        num_pages = 1
+    else:
+        mset = enquire.get_mset(offset, n_per_page)
+        num_pages = int(ceil(float(mset.get_matches_estimated()) / n_per_page))
 
-    num_pages = int(ceil(float(mset.get_matches_estimated()) / n_per_page))
+    pks = [match.document.get_data() for match in mset]
 
     # filter doesn't guarantee an order, so we need to get all the
     # possible models then look them up to get the ordering
@@ -190,12 +197,17 @@ def ajax_query_search_query(request, n_per_page=10):
 
 @ajax_view
 def ajax_query_view(request):
+    try:
+        n_per_page = int(request.GET['n_per_page'])
+    except (KeyError, ValueError), e:
+        n_per_page = 10
+
     if request.GET.get('search',  ''):
         func = ajax_query_search_query
     else:
         func = ajax_query_params_query
 
-    object_list, num_pages = func(request)
+    object_list, num_pages = func(request, n_per_page)
 
     return dict(extensions=[ajax_details(e) for e in object_list],
                 numpages=num_pages)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]