Fixed pagiatation
This commit is contained in:
parent
9f29ea603f
commit
4ea8d16253
@ -512,12 +512,12 @@ body {
|
||||
height: 60px;
|
||||
box-shadow: 0 0 2px #C09F80;
|
||||
grid-area: header;
|
||||
background-color: white; }
|
||||
background-color: white;
|
||||
padding-left: 25px; }
|
||||
.LP-Header__Navigation {
|
||||
flex-grow: 2; }
|
||||
.LP-Header__Logo {
|
||||
height: 45px;
|
||||
margin: 25px;
|
||||
object-fit: cover;
|
||||
max-height: 100%;
|
||||
width: 225px;
|
||||
@ -550,8 +550,8 @@ body {
|
||||
|
||||
@media (max-width: 650px) {
|
||||
.LP-Header {
|
||||
padding-left: 40px;
|
||||
width: calc(100% - 40px);
|
||||
padding-left: 60px;
|
||||
width: calc(100% - 60px);
|
||||
position: fixed;
|
||||
z-index: 10; } }
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
{% load lostplaces %}
|
||||
|
||||
{% if is_paginated %}
|
||||
<div class="LP-Pagination">
|
||||
<ul class="LP-Pagination__List">
|
||||
@ -16,15 +18,17 @@
|
||||
<span class="LP-Pagination__Previous">previous</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for i in page_obj.paginator %}
|
||||
{% if i.number == page_obj.number %}
|
||||
|
||||
{% for i in page_obj.paginator|proper_paginate:page_obj.number %}
|
||||
{% if i == page_obj.number %}
|
||||
<li class="LP-Pagination__Item LP-Pagination__Item--number LP-Pagination__Item--current">
|
||||
{% else %}
|
||||
<li class="LP-Pagination__Item LP-Pagination__Item--number">
|
||||
{% endif %}
|
||||
<a href="?page={{i.number}}" class="LP-Link"><span class="LP-Pagination__Number">{{i.number}}</span></a>
|
||||
<a href="?page={{i}}" class="LP-Link"><span class="LP-Pagination__Number">{{i}}</span></a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
{% if page_obj.has_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>
|
||||
|
0
lostplaces/lostplaces_app/templatetags/__init__.py
Normal file
0
lostplaces/lostplaces_app/templatetags/__init__.py
Normal file
22
lostplaces/lostplaces_app/templatetags/lostplaces.py
Normal file
22
lostplaces/lostplaces_app/templatetags/lostplaces.py
Normal 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
|
@ -50,7 +50,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
|
||||
success_message = 'User created.'
|
||||
|
||||
class PlaceListView(IsAuthenticated, ListView):
|
||||
paginate_by = 5
|
||||
paginate_by = 2
|
||||
model = Place
|
||||
template_name = 'place/place_list.html'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user