New templatetag for pagination

This commit is contained in:
Ales (Shagi) Zabala Alava 2021-03-02 16:16:55 +01:00
parent 28269a3a93
commit bf3cf6f217
2 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1,28 @@
{% load i18n %}
{% load custom_gas_tags %}
{% if page %}
<nav class="pagination">
<ul>
{% if page.has_previous %}
<li>
<a href="?{% url_replace request page=page.previous_page_number %}">{% trans "Previous" %}</a>
</li>
{% endif %}
<li class="current">
{% blocktrans with number=page.number total=page.paginator.num_pages %}
Page {{ number }} of {{ total }}
{% endblocktrans %}
</li>
{% if page.has_next %}
<li><a href="?{% url_replace request page=page.next_page_number %}">{% trans "Next" %}</a></li>
{% endif %}
</ul>
<p>
{% blocktrans with start=page.start_index end=page.end_index total_objects=page.paginator.count %}
From {{ start }} to {{ end }} of {{ total_objects }} total items.
{% endblocktrans %}
</p>
</nav>
{% endif %}

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
import json
from urllib.parse import urlencode
from django import template
from django.utils.html import mark_safe
@ -39,3 +40,23 @@ def display_boolean(value):
else:
render = '<i class="fas fa-times"></i>'
return mark_safe(render)
@register.simple_tag
def url_replace(request, **kwargs):
query = request.GET.dict()
query.update(kwargs)
return urlencode(query)
@register.inclusion_tag("gas/tags/pagination.html")
def pagination(request, page):
return {
'request': request,
'page': page,
}
@register.filter
def to_json(data):
return mark_safe(json.dumps(data))