# HG changeset patch # User ymh # Date 1386100504 -3600 # Node ID 216b3f9582aab690168269cf5d1ea37fb1843419 # Parent 470ea7806537da4a332ed9aec633c73c0423ae32 improve paginator on list. Should closes bug #14. diff -r 470ea7806537 -r 216b3f9582aa src/p4l/config.py.tmpl --- a/src/p4l/config.py.tmpl Tue Dec 03 13:54:30 2013 +0100 +++ b/src/p4l/config.py.tmpl Tue Dec 03 20:55:04 2013 +0100 @@ -161,6 +161,9 @@ # pagination of the list of record NB_RECORDS_BY_PAGE = 20 +#some control on the pagination appareance +PAGINATOR_VISIBLE_RANGE = 5 #number of pages +PAGINATOR_START_RANGE = 2 #number of pages kept at the beggining and at the end of the range # url of the sesame repository containing all the rdf referentials SPARQL_QUERY_ENDPOINT = "http://localhost:8080/openrdf-sesame/repositories/plan4learning" @@ -172,3 +175,4 @@ 'env' : {'PYTHONPATH': '/Users/ymh/dev/venvs/p4l/lib/python2.7/site-packages'} } + diff -r 470ea7806537 -r 216b3f9582aa src/p4l/search/views.py --- a/src/p4l/search/views.py Tue Dec 03 13:54:30 2013 +0100 +++ b/src/p4l/search/views.py Tue Dec 03 20:55:04 2013 +0100 @@ -33,11 +33,14 @@ from django.conf import settings +from django.core.paginator import InvalidPage +from django.http.response import Http404 from django.template.context import RequestContext from haystack.query import SearchQuerySet from haystack.views import SearchView, search_view_factory from p4l.search.forms import RecordSearchForm +from p4l.utils import P4lPaginator class RecordSearchView(SearchView): @@ -52,3 +55,32 @@ @classmethod def as_view(cls): return search_view_factory(view_class=cls) + + def build_page(self): + """ + Paginates the results appropriately. + + In case someone does not want to use Django's built-in pagination, it + should be a simple matter to override this method to do what they would + like. + """ + try: + page_no = int(self.request.GET.get('page', 1)) + except (TypeError, ValueError): + raise Http404("Not a valid number for page.") + + if page_no < 1: + raise Http404("Pages should be 1 or greater.") + + start_offset = (page_no - 1) * self.results_per_page + self.results[start_offset:start_offset + self.results_per_page] + + paginator = P4lPaginator(self.results, self.results_per_page) + + try: + page = paginator.page(page_no) + except InvalidPage: + raise Http404("No such page!") + + return (paginator, page) + diff -r 470ea7806537 -r 216b3f9582aa src/p4l/settings.py --- a/src/p4l/settings.py Tue Dec 03 13:54:30 2013 +0100 +++ b/src/p4l/settings.py Tue Dec 03 20:55:04 2013 +0100 @@ -212,6 +212,10 @@ } NB_RECORDS_BY_PAGE = 20 +#some control on the pagination appareance +PAGINATOR_VISIBLE_RANGE = 5 #number of visible pages +PAGINATOR_START_RANGE = 2 #number of pages kept at the beggining and at the end of the range + HAYSTACK_CONNECTIONS = { 'default': { @@ -285,6 +289,7 @@ SCRIPT_WAIT = .250 SCRIPT_MAX_WAIT = 40 # * SCRIPT_WAIT = 10 sec + from config import * # @UnusedWildImport if not "SRC_BASE_URL" in locals(): diff -r 470ea7806537 -r 216b3f9582aa src/p4l/templates/p4l/home.html --- a/src/p4l/templates/p4l/home.html Tue Dec 03 13:54:30 2013 +0100 +++ b/src/p4l/templates/p4l/home.html Tue Dec 03 20:55:04 2013 +0100 @@ -25,19 +25,23 @@ -