kopia lustrzana https://github.com/hholzgra/maposmatic/
				
				
				
			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 <maxime.hadjinlian@gmail.com> Acked-by: Thomas Petazzoni <thomas.petazzoni@enix.org> Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>stable
							rodzic
							
								
									dfa4dcf4da
								
							
						
					
					
						commit
						f19e2a368a
					
				| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,7 @@
 | 
			
		|||
 | 
			
		||||
{% block page %}
 | 
			
		||||
<div class="mapsearch">
 | 
			
		||||
  <form action="{% url maps %}" method="post">{{ form.query }}<input type="submit" value="{% trans "Search" %}" /></form>
 | 
			
		||||
  <form action="{% url maps %}" method="get">{{ form.query }}<input type="submit" value="{% trans "Search" %}" /></form>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<h1><a href="{% url maps %}">{% trans "Maps" %}</a> <a href="/feeds/maps/"><img src="/smedia/feed.png" class="feedicon" title="{% trans "MapOSMatic maps feed" %}" /></h1>
 | 
			
		||||
| 
						 | 
				
			
			@ -42,9 +42,9 @@
 | 
			
		|||
 | 
			
		||||
{% ifnotequal maps.paginator.num_pages 1 %}
 | 
			
		||||
<div class="pagination">
 | 
			
		||||
  {% if maps.has_previous %}<a href="?page={{ maps.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %}
 | 
			
		||||
  {% if maps.has_previous %}<a href="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %}
 | 
			
		||||
  <span class="current">{% trans "Page" %} {{ maps.number }} {% trans "of" %} {{ maps.paginator.num_pages }}</span>
 | 
			
		||||
  {% if maps.has_next %}<a href="?page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %}
 | 
			
		||||
  {% if maps.has_next %}<a href="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
{% endifnotequal %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,9 +67,9 @@
 | 
			
		|||
 | 
			
		||||
{% ifnotequal maps.paginator.num_pages 1 %}
 | 
			
		||||
<div class="pagination">
 | 
			
		||||
  {% if maps.has_previous %}<a href="?page={{ maps.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %}
 | 
			
		||||
  {% if maps.has_previous %}<a href="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %}
 | 
			
		||||
  <span class="current">{% trans "Page" %} {{ maps.number }} {% trans "of" %} {{ maps.paginator.num_pages }}</span>
 | 
			
		||||
  {% if maps.has_next %}<a href="?page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %}
 | 
			
		||||
  {% if maps.has_next %}<a href="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
{% endifnotequal %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue