From eaf5f8122eb3fe304a54b608ac8eae3abee8b1ad Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 20 Jun 2014 21:49:06 +0200 Subject: [PATCH] Fix paginating issues --- blog/views.py | 8 ++++-- gergelypolonkaiweb/templates/paginator.html | 30 +++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/blog/views.py b/blog/views.py index 23c8e35..5bdaf10 100644 --- a/blog/views.py +++ b/blog/views.py @@ -10,7 +10,8 @@ def listing(request, tag, year, month, day, page): kwargs = {} kwargs['draft'] = False - view = index + view = 'index' + if (tag == None): view = "index" else: @@ -36,7 +37,10 @@ def listing(request, tag, year, month, day, page): except EmptyPage: posts = paginator.page(paginator.num_pages) - return render(request, 'blog/listing.html', { 'posts': posts, 'view': "blog:" + view }) + if paginator.num_pages > 1: + view = view + 'page' + + return render(request, 'blog/listing.html', { 'posts': posts, 'tag': tag, 'view': "blog:" + view }) def index(request): return listing(request, None, None, None, None, 1) diff --git a/gergelypolonkaiweb/templates/paginator.html b/gergelypolonkaiweb/templates/paginator.html index 14d689b..10ea27b 100644 --- a/gergelypolonkaiweb/templates/paginator.html +++ b/gergelypolonkaiweb/templates/paginator.html @@ -1,19 +1,39 @@ {% if list.paginator.num_pages > 1 %}
{% if list.number > 1 %} - First + {% if tag %} + First + {% else %} + First + {% endif %} {% endif %} {% if list.has_previous and list.number != 2 %} - Previous + {% if tag %} + Previous + {% else %} + Previous + {% endif %} {% endif %} {% for i in posts.paginator.page_range %} - {% if list.number != i %}{% endif %}{{ i }}{% if list.number != i %}{% endif %} + {% if tag %} + {% if list.number != i %}{% endif %}{{ i }}{% if list.number != i %}{% endif %} + {% else %} + {% if list.number != i %}{% endif %}{{ i }}{% if list.number != i %}{% endif %} + {% endif %} {% endfor %} {% if list.has_next and list.number != list.paginator.num_pages|add:-1 %} - Next + {% if tag %} + Next + {% else %} + Next + {% endif %} {% endif %} {% if list.number < list.paginator.num_pages %} - Last + {% if tag %} + Last + {% else %} + Last + {% endif %} {% endif %}
{% endif %}