Fix paginating issues

This commit is contained in:
Gergely Polonkai 2014-06-20 21:49:06 +02:00
parent 51b246a037
commit eaf5f8122e
2 changed files with 31 additions and 7 deletions

View File

@ -10,7 +10,8 @@ def listing(request, tag, year, month, day, page):
kwargs = {} kwargs = {}
kwargs['draft'] = False kwargs['draft'] = False
view = index view = 'index'
if (tag == None): if (tag == None):
view = "index" view = "index"
else: else:
@ -36,7 +37,10 @@ def listing(request, tag, year, month, day, page):
except EmptyPage: except EmptyPage:
posts = paginator.page(paginator.num_pages) 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): def index(request):
return listing(request, None, None, None, None, 1) return listing(request, None, None, None, None, 1)

View File

@ -1,19 +1,39 @@
{% if list.paginator.num_pages > 1 %} {% if list.paginator.num_pages > 1 %}
<div class="paginator"> <div class="paginator">
{% if list.number > 1 %} {% if list.number > 1 %}
<a href="{% url view tag=tag %}">First</a> {% if tag %}
<a href="{% url view page=1 tag=tag %}">First</a>
{% else %}
<a href="{% url view page=1 %}">First</a>
{% endif %}
{% endif %} {% endif %}
{% if list.has_previous and list.number != 2 %} {% if list.has_previous and list.number != 2 %}
<a href="{% url view 'page'=list.previous_page_number 'tag'=tag %}">Previous</a> {% if tag %}
<a href="{% url view page=list.previous_page_number tag=tag %}">Previous</a>
{% else %}
<a href="{% url view page=list.previous_page_number %}">Previous</a>
{% endif %}
{% endif %} {% endif %}
{% for i in posts.paginator.page_range %} {% for i in posts.paginator.page_range %}
{% if list.number != i %}<a href="{% url view 'page'=i %}">{% endif %}{{ i }}{% if list.number != i %}</a>{% endif %} {% if tag %}
{% if list.number != i %}<a href="{% url view page=i tag=tag %}">{% endif %}{{ i }}{% if list.number != i %}</a>{% endif %}
{% else %}
{% if list.number != i %}<a href="{% url view page=i %}">{% endif %}{{ i }}{% if list.number != i %}</a>{% endif %}
{% endif %}
{% endfor %} {% endfor %}
{% if list.has_next and list.number != list.paginator.num_pages|add:-1 %} {% if list.has_next and list.number != list.paginator.num_pages|add:-1 %}
<a href="{% url view 'page'=list.next_page_number 'tag'=tag %}">Next</a> {% if tag %}
<a href="{% url view page=list.next_page_number tag=tag %}">Next</a>
{% else %}
<a href="{% url view page=list.next_page_number %}">Next</a>
{% endif %}
{% endif %} {% endif %}
{% if list.number < list.paginator.num_pages %} {% if list.number < list.paginator.num_pages %}
<a href="{% url view 'page'=list.paginator.num_pages 'tag'=tag %}">Last</a> {% if tag %}
<a href="{% url view page=list.paginator.num_pages tag=tag %}">Last</a>
{% else %}
<a href="{% url view page=list.paginator.num_pages %}">Last</a>
{% endif %}
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}