From 960b16d1b725f02d9f6e55c4d7840422c488cd49 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 22 Aug 2011 12:32:05 -0700 Subject: [PATCH] catch EmptyPage errors on search --- apps/search/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/search/views.py b/apps/search/views.py index 235a593a..8ca86748 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -19,6 +19,7 @@ def search(request): type_ = query.get('type') or None types = {'a': 'addon', 'l': 'library'} page = query.get('page') or 1 + limit = 20 filters = {} @@ -37,7 +38,10 @@ def search(request): filters['type'] = type_ qs = package_search(q, **filters).facet(copies={'terms': {'field':'copies_count'}}) - results['pager'] = Paginator(qs, per_page=20).page(page) + try: + results['pager'] = Paginator(qs, per_page=limit).page(page) + except EmptyPage: + results['pager'] = Paginator(qs, per_page=limit).page(1) facets = _facets(results['pager'].object_list.facets) facets['everyone_total'] = len(qs) template = 'results.html'