From f19e2a368af12c5d85d580868fd960e86c22ef84 Mon Sep 17 00:00:00 2001 From: Maxime Hadjinlian Date: Mon, 21 Jun 2010 00:55:58 +0200 Subject: [PATCH] Add pagination when searching Implements pagination when searching in the map list. The search method is now a GET (was POST), it's now used by the pagination links. An argument is passed so the pagination is done on the searched list. Signed-off-by: Maxime Hadjinlian Acked-by: Thomas Petazzoni Signed-off-by: Maxime Petazzoni --- www/maposmatic/views.py | 25 ++++++++++--------------- www/templates/maposmatic/all_maps.html | 10 +++++----- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py index c3ae2d35..3dc8d815 100644 --- a/www/maposmatic/views.py +++ b/www/maposmatic/views.py @@ -141,21 +141,16 @@ def all_maps(request): terms, when provided.""" map_list = None + form = forms.MapSearchForm(request.GET) - if request.method == 'POST': - form = forms.MapSearchForm(request.POST) - if form.is_valid(): - map_list = (models.MapRenderingJob.objects - .order_by('maptitle') - .filter(status=2) - .filter(maptitle__icontains=form.cleaned_data['query'])) - if len(map_list) == 1: - return HttpResponseRedirect(reverse('job-by-id', - args=[map_list[0].id])) - - # TODO: find a way to have a working paginator. For now, limit to - # ITEMS_PER_PAGE results. - map_list = map_list[:www.settings.ITEMS_PER_PAGE] + if form.is_valid(): + map_list = (models.MapRenderingJob.objects + .order_by('maptitle') + .filter(status=2) + .filter(maptitle__icontains=form.cleaned_data['query'])) + if len(map_list) == 1: + return HttpResponseRedirect(reverse('job-by-id', + args=[map_list[0].id])) else: form = forms.MapSearchForm() @@ -177,7 +172,7 @@ def all_maps(request): return render_to_response('maposmatic/all_maps.html', { 'maps': maps, 'letters': helpers.get_letters(), - 'form': form }, + 'form': form, 'is_search': form.is_valid() }, context_instance=MapOSMaticRequestContext(request)) def all_maps_by_letter(request, letter): diff --git a/www/templates/maposmatic/all_maps.html b/www/templates/maposmatic/all_maps.html index e940ee5c..e64a5c62 100644 --- a/www/templates/maposmatic/all_maps.html +++ b/www/templates/maposmatic/all_maps.html @@ -31,7 +31,7 @@ {% block page %}
-
{{ form.query }}
+
{{ form.query }}

{% trans "Maps" %}

@@ -42,9 +42,9 @@ {% ifnotequal maps.paginator.num_pages 1 %} {% endifnotequal %} @@ -67,9 +67,9 @@ {% ifnotequal maps.paginator.num_pages 1 %} {% endifnotequal %}