The pagination allow the users to navigate quickly through a big list of pages. It's available in Jobs and Maps pages. We display : [1, 2, (...), n-1, n, n+1, (...), t-1, t ]
The letter pagination is to disappear in the next commit. Signed-off-by: Maxime Hadjinlian <[email protected]> --- www/maposmatic/helpers.py | 22 +++++++++++++++++ www/maposmatic/views.py | 10 ++++--- www/media/style.css | 5 ++++ www/templates/maposmatic/all_jobs.html | 16 +----------- www/templates/maposmatic/all_maps.html | 16 +----------- www/templates/maposmatic/paginator.html | 40 +++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 32 deletions(-) create mode 100644 www/templates/maposmatic/paginator.html diff --git a/www/maposmatic/helpers.py b/www/maposmatic/helpers.py index 0a70e26..45b96d4 100644 --- a/www/maposmatic/helpers.py +++ b/www/maposmatic/helpers.py @@ -155,3 +155,25 @@ def get_letters(): # who don't? return [chr(i) for i in xrange(ord('A'), ord('Z')+1)] +def get_pages_list(page, paginator): + """Returns a list of number. + It contains the id of the pages to display for a page given.""" + + # Navigation pages + nav = {} + page_list = [] + last = False + + for i in [1, 2, + page.number-1, page.number, page.number+1, + paginator.num_pages-1, paginator.num_pages]: + nav[i] = True + + for i in xrange(1, paginator.num_pages+1): + if nav.has_key(i): + if last and i - last > 1: + page_list.append('...') + page_list.append(i) + last = i + return page_list + diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py index 3dc8d81..4e899df 100644 --- a/www/maposmatic/views.py +++ b/www/maposmatic/views.py @@ -108,8 +108,8 @@ def job(request, job_id): refresh = www.settings.REFRESH_JOB_RENDERING return render_to_response('maposmatic/job-page.html', - { 'job' : job, 'single': True, - 'redirected' : isredirected, + { 'job': job, 'single': True, + 'redirected': isredirected, 'refresh': refresh, 'refresh_ms': (refresh*1000) }, context_instance=MapOSMaticRequestContext(request)) @@ -133,7 +133,8 @@ def all_jobs(request): jobs = paginator.page(paginator.num_pages) return render_to_response('maposmatic/all_jobs.html', - { 'jobs' : jobs }, + { 'jobs': jobs, + 'pages': helpers.get_pages_list(jobs, paginator) }, context_instance=MapOSMaticRequestContext(request)) def all_maps(request): @@ -172,7 +173,8 @@ def all_maps(request): return render_to_response('maposmatic/all_maps.html', { 'maps': maps, 'letters': helpers.get_letters(), - 'form': form, 'is_search': form.is_valid() }, + 'form': form, 'is_search': form.is_valid(), + 'pages': helpers.get_pages_list(maps, paginator) }, context_instance=MapOSMaticRequestContext(request)) def all_maps_by_letter(request, letter): diff --git a/www/media/style.css b/www/media/style.css index 77a80c3..794f6ce 100644 --- a/www/media/style.css +++ b/www/media/style.css @@ -39,6 +39,11 @@ a img { border: none; } +a.current { + font-weight: bold; + font-size: larger; +} + img { -ms-interpolation-mode: bicubic; } diff --git a/www/templates/maposmatic/all_jobs.html b/www/templates/maposmatic/all_jobs.html index 0fb97ff..28bcd05 100644 --- a/www/templates/maposmatic/all_jobs.html +++ b/www/templates/maposmatic/all_jobs.html @@ -41,13 +41,7 @@ requests received during the last 24 hours, starting from the most recent one.{% endblocktrans %} </p> -{% ifnotequal jobs.paginator.num_pages 1 %} -<div class="pagination"> - {% if jobs.has_previous %}<a class="prevlink" href="?page={{ jobs.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %} - <span class="current">{% trans "Page" %} {{ jobs.number }} {% trans "of" %} {{ jobs.paginator.num_pages }}</span> - {% if jobs.has_next %}<a class="nextlink" href="?page={{ jobs.next_page_number }}">{% trans "Next" %} »</a>{% endif %} -</div> -{% endifnotequal %} +{% with jobs as data %}{% include "maposmatic/paginator.html" %}{% endwith %} {% for job in jobs.object_list %} <div class="job {% cycle jobodd,jobeven %}"> @@ -55,13 +49,7 @@ recent one.{% endblocktrans %} </div> {% endfor %} -{% ifnotequal jobs.paginator.num_pages 1 %} -<div class="pagination"> - {% if jobs.has_previous %}<a class="prevlink" href="?page={{ jobs.previous_page_number }}">« {% trans "Previous" %}</a>{% endif %} - <span class="current">{% trans "Page" %} {{ jobs.number }} {% trans "of" %} {{ jobs.paginator.num_pages }}</span> - {% if jobs.has_next %}<a class="nextlink" href="?page={{ jobs.next_page_number }}">{% trans "Next" %} »</a>{% endif %} -</div> -{% endifnotequal %} +{% with jobs as data %}{% include "maposmatic/paginator.html" %}{% endwith %} {% else %} <p> diff --git a/www/templates/maposmatic/all_maps.html b/www/templates/maposmatic/all_maps.html index e64a5c6..f713511 100644 --- a/www/templates/maposmatic/all_maps.html +++ b/www/templates/maposmatic/all_maps.html @@ -40,13 +40,7 @@ <a href="{% url maps %}"{% if not current_letter %} class="selectedletter"{% endif %}>{% trans "All" %}</a> - {% for l in letters %}<a href="{% url maps-by-letter l %}"{% ifequal l current_letter %} class="selectedletter"{% endifequal %}>{{ l }}</a>{% if not forloop.last %} - {% endif %}{% endfor %} </p> -{% ifnotequal maps.paginator.num_pages 1 %} -<div class="pagination"> - {% 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="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %} -</div> -{% endifnotequal %} +{% with maps as data %}{% with form.cleaned_data.query as query %}{% include "maposmatic/paginator.html" %}{% endwith %}{% endwith %} {% comment %}For Django 1.0.x compatibility. With Django >= 1.1 we should use the empty tag.{% endcomment %} {% if maps.object_list|length %} @@ -65,12 +59,6 @@ </p> {% endif %} -{% ifnotequal maps.paginator.num_pages 1 %} -<div class="pagination"> - {% 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="?{% if is_search %}query={{ form.cleaned_data.query|urlencode }}&{% endif %}page={{ maps.next_page_number }}">{% trans "Next" %} »</a>{% endif %} -</div> -{% endifnotequal %} +{% with maps as data %}{% with form.cleaned_data.query as query %}{% include "maposmatic/paginator.html" %}{% endwith %}{% endwith %} {% endblock %} diff --git a/www/templates/maposmatic/paginator.html b/www/templates/maposmatic/paginator.html new file mode 100644 index 0000000..ad09c12 --- /dev/null +++ b/www/templates/maposmatic/paginator.html @@ -0,0 +1,40 @@ +{% comment %} + coding: utf-8 + + maposmatic, the web front-end of the MapOSMatic city map generation system + Copyright (C) 2009 David Decotigny + Copyright (C) 2009 Frédéric Lehobey + Copyright (C) 2009 David Mentré + Copyright (C) 2009 Maxime Petazzoni + Copyright (C) 2009 Thomas Petazzoni + Copyright (C) 2009 Gaël Utard + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +{% endcomment %} + + +{% load i18n %} + +{% load extratags %} + +{% ifnotequal data.paginator.num_pages 1 %} +<div class="pagination"> + {% if data.has_previous %}<a href="?{% if is_search %}query={{ query|urlencode }}&{% endif %}page={{ data.previous_page_number }}">« {% trans "Previous" %}</a> ·{% endif %} + {% for num in pages %} + {% ifequal num "..." %}{{ num }}{% else %}<a href="?{% if is_search %}query={{ query|urlencode }}&{% endif %}page={{ num }}"{% ifequal num data.number %} class="current"{% endifequal %}>{{ num }}</a>{% endifequal %} + {% endfor %} + {% if data.has_next %}· <a href="?{% if is_search %}query={{ query|urlencode }}&{% endif %}page={{ data.next_page_number }}">{% trans "Next" %} »</a>{% endif %} +</div> +{% endifnotequal %} + -- 1.7.1
