Added pagination to template

This commit is contained in:
Claudio Maggioni 2018-09-09 17:31:47 +02:00
parent e646089dd6
commit e991a17151
4 changed files with 58 additions and 2 deletions

View file

@ -4,4 +4,4 @@ POSTGRES_DB=arrowcounter
POSTGRES_USER=arrowcounter
POSTGRES_PASSWORD=password
SECURITY_KEY=malusa
ALLOWED_HOSTS=192.168.1.201
ALLOWED_HOSTS=*

View file

@ -4,6 +4,7 @@
{% block content %}
<h1 class="center">Counts</h1>
{% include 'pagination.html' %}
<table class="centered">
<thead>
<tr>
@ -37,6 +38,7 @@
{% endfor %}
</tbody>
</table>
{% include 'pagination.html' %}
<div class="fixed-action-btn">
<a class="btn-floating btn-large waves-effect waves-light red"
href="{% url "count_new" %}">

View file

@ -0,0 +1,47 @@
<ul class="center pagination">
<li class="{% if page >= 2 %}waves-effect{% else %}disabled{% endif %}">
<a class="item"
href="{% if page >= 2 %}?page={{ page|add:'-1' }}{% else %}#{% endif %}">
<i class="material-icons">chevron_left</i>
</a>
</li>
{% if page >= 3 %}
<li class="waves-effect">
<a class="item" href="?page={{ page|add:'-2' }}">
{{ page|add:"-2" }}
</a>
</li>
{% endif %}
{% if page >= 2 %}
<li class="waves-effect">
<a class="item" href="?page={{ page|add:'-1' }}">
{{ page|add:"-1" }}
</a>
</li>
{% endif %}
<li class="active">
<a class="active item" href="#">
{{ page }}
</a>
</li>
{% if pageCount >= page|add:"1" %}
<li class="waves-effect">
<a class="item" href="?page={{ page|add:'1' }}">
{{ page|add:"1" }}
</a>
</li>
{% endif %}
{% if pageCount >= page|add:"2" %}
<li class="waves-effect">
<a class="item" href="?page={{ page|add:'2' }}">
{{ page|add:"2" }}
</a>
</li>
{% endif %}
<li class="{% if pageCount >= page|add:'1' %}waves-effect{% else %}disabled{% endif %}">
<a class="item"
href="{% if pageCount >= page|add:'1' %}?page={{ page|add:'1' }}{% else %}#{% endif %}">
<i class="material-icons">chevron_right</i>
</a>
</li>
</ul>

View file

@ -30,8 +30,15 @@ def arrow_count_list(request):
finish = settings.ITEMS_PER_PAGE + start
counts = ArrowCount.objects.order_by('-date') \
.filter(user = request.user)[start:finish]
pageCount = ArrowCount.objects.filter(user = request.user).count() / \
settings.ITEMS_PER_PAGE
template = loader.get_template('counter/list.html')
return HttpResponse(template.render({'counts': counts}, request))
return HttpResponse(template.render({
'counts': counts,
'pageCount': pageCount,
'page': page
}, request))
class NewArrowCount(generic.CreateView):
form_class = ArrowCountForm