Fixed pagiatation

This commit is contained in:
reverend 2020-08-16 16:29:04 +02:00
parent 9f29ea603f
commit 4ea8d16253
5 changed files with 41 additions and 15 deletions

View File

@ -512,12 +512,12 @@ body {
height: 60px; height: 60px;
box-shadow: 0 0 2px #C09F80; box-shadow: 0 0 2px #C09F80;
grid-area: header; grid-area: header;
background-color: white; } background-color: white;
padding-left: 25px; }
.LP-Header__Navigation { .LP-Header__Navigation {
flex-grow: 2; } flex-grow: 2; }
.LP-Header__Logo { .LP-Header__Logo {
height: 45px; height: 45px;
margin: 25px;
object-fit: cover; object-fit: cover;
max-height: 100%; max-height: 100%;
width: 225px; width: 225px;
@ -550,8 +550,8 @@ body {
@media (max-width: 650px) { @media (max-width: 650px) {
.LP-Header { .LP-Header {
padding-left: 40px; padding-left: 60px;
width: calc(100% - 40px); width: calc(100% - 60px);
position: fixed; position: fixed;
z-index: 10; } } z-index: 10; } }

View File

@ -1,3 +1,5 @@
{% load lostplaces %}
{% if is_paginated %} {% if is_paginated %}
<div class="LP-Pagination"> <div class="LP-Pagination">
<ul class="LP-Pagination__List"> <ul class="LP-Pagination__List">
@ -15,16 +17,18 @@
<li class="LP-Pagination__Item LP-Pagination__Item--previous LP-Pagination__Item--disabled"> <li class="LP-Pagination__Item LP-Pagination__Item--previous LP-Pagination__Item--disabled">
<span class="LP-Pagination__Previous">previous</span> <span class="LP-Pagination__Previous">previous</span>
</li> </li>
{% endif %} {% endif %}
{% for i in page_obj.paginator %}
{% if i.number == page_obj.number %} {% for i in page_obj.paginator|proper_paginate:page_obj.number %}
<li class="LP-Pagination__Item LP-Pagination__Item--number LP-Pagination__Item--current"> {% if i == page_obj.number %}
{% else %} <li class="LP-Pagination__Item LP-Pagination__Item--number LP-Pagination__Item--current">
<li class="LP-Pagination__Item LP-Pagination__Item--number"> {% else %}
{% endif %} <li class="LP-Pagination__Item LP-Pagination__Item--number">
<a href="?page={{i.number}}" class="LP-Link"><span class="LP-Pagination__Number">{{i.number}}</span></a> {% endif %}
</li> <a href="?page={{i}}" class="LP-Link"><span class="LP-Pagination__Number">{{i}}</span></a>
{% endfor %} </li>
{% endfor %}
{% if page_obj.has_next %} {% if page_obj.has_next %}
<li class="LP-Pagination__Item LP-Pagination__Item--next"> <li class="LP-Pagination__Item LP-Pagination__Item--next">
<a href="?page={{ page_obj.next_page_number }}" class="LP-Link"><span class="LP-Pagination__Next">next</span></a> <a href="?page={{ page_obj.next_page_number }}" class="LP-Link"><span class="LP-Pagination__Next">next</span></a>

View File

@ -0,0 +1,22 @@
from django import template
register = template.Library()
@register.filter(name='proper_paginate')
def proper_paginate(paginator, current_page, neighbors=2):
if paginator.num_pages > 2*neighbors:
start_index = max(1, current_page-neighbors)
end_index = min(paginator.num_pages, current_page + neighbors)
if end_index < start_index + 2*neighbors:
end_index = start_index + 2*neighbors
elif start_index > end_index - 2*neighbors:
start_index = end_index - 2*neighbors
if start_index < 1:
end_index -= start_index
start_index = 1
elif end_index > paginator.num_pages:
start_index -= (end_index-paginator.num_pages)
end_index = paginator.num_pages
page_list = [f for f in range(start_index, end_index+1)]
return page_list[:(2*neighbors + 1)]
return paginator.page_range

View File

@ -50,7 +50,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
success_message = 'User created.' success_message = 'User created.'
class PlaceListView(IsAuthenticated, ListView): class PlaceListView(IsAuthenticated, ListView):
paginate_by = 5 paginate_by = 2
model = Place model = Place
template_name = 'place/place_list.html' template_name = 'place/place_list.html'