Add generic pagination tempalte

This commit is contained in:
Mario Hüttel 2021-08-14 02:20:45 +02:00
parent e8538cd534
commit a9bcda045a
3 changed files with 42 additions and 68 deletions

View File

@ -0,0 +1,25 @@
{% if paginator.has_other_pages %}
<nav aria-label="{{aria_label}}">
<ul class="pagination">
{% if paginator.has_previous %}
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.previous_page_number}}">&laquo;</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&laquo;</span></li>
{% endif %}
{% for i in paginator.paginator.page_range %}
{% if i <= paginator.number|add:5 and i >= paginator.number|add:-5 %}
{% if i == paginator.number %}
<li class="page-item active"><a class="page-link" href="?{{get_param}}={{i}}">{{i}}</a></li>
{% else %}
<li class="page-item"><a class="page-link" href="?{{get_param}}={{i}}">{{i}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
{% if paginator.has_next %}
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.next_page_number}}">&raquo;</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
{% endif %}
</ul>
</nav>
{% endif %}

View File

@ -35,24 +35,7 @@
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
<nav aria-label="Storage Navigation"> {% include 'paginator.html' with paginator=storages get_param='storage_page' aria_label='Storage Page Navigation' %}
<ul class="pagination">
{% if storages.number > 1 %}
<li class="page-item"><a class="page-link" href="?storage_page={{storages.previous_page_number}}">&laquo;</a></li>
<li class="page-item"><a class="page-link" href="?storage_page={{storages.previous_page_number}}">{{storages.previous_page_number}}</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&laquo;</span></li>
{% endif %}
<li class="page-item active"><span class="page-link">{{storages.number}}</span></li>
{% if storages.paginator.num_pages > storages.number %}
<li class="page-item"><a class="page-link" href="?storage_page={{storages.next_page_number}}">{{storages.next_page_number}}</a></li>
<li class="page-item"><a class="page-link" href="?storage_page={{storages.next_page_number}}">&raquo;</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
{% endif %}
</ul>
</nav>
</div> </div>
</div> </div>

View File

@ -31,58 +31,24 @@
</li></a> </li></a>
{% endfor %} {% endfor %}
</div> </div>
<nav aria-label="Low Stock Navigation"> {% include 'paginator.html' with paginator=low_stocks get_param='low_stock_page' aria_label='Low Stock Page Navigation' %}
<ul class="pagination">
{% if low_stocks.number > 1 %}
<li class="page-item"><a class="page-link" href="?low_stock_page={{low_stocks.previous_page_number}}">&laquo;</a></li>
<li class="page-item"><a class="page-link" href="?low_stock_page={{low_stocks.previous_page_number}}">{{low_stocks.previous_page_number}}</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&laquo;</span></li>
{% endif %}
<li class="page-item active"><span class="page-link">{{low_stocks.number}}</span></li>
{% if low_stocks.paginator.num_pages > low_stocks.number %}
<li class="page-item"><a class="page-link" href="?low_stock_page={{low_stocks.next_page_number}}">{{low_stocks.next_page_number}}</a></li>
<li class="page-item"><a class="page-link" href="?low_stock_page={{low_stocks.next_page_number}}">&raquo;</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
{% endif %}
</ul>
</nav>
</div> </div>
<div class="col-md"> <div class="col-md">
<h1>Storages</h1> <h1>Storages</h1>
<div class="list-group"> <div class="list-group">
{% for storage in storages %} {% for storage in storages %}
<a href="{% url 'parts-stocks-detail' uuid=storage.id %}" class="text-decoration-none"> <a href="{% url 'parts-stocks-detail' uuid=storage.id %}" class="text-decoration-none">
<li class="list-group-item list-group-item-action justify-content-between align-items-center d-flex"> <li class="list-group-item list-group-item-action justify-content-between align-items-center d-flex">
<div> <div>
<h5>{{storage.name}}</h5> <h5>{{storage.name}}</h5>
Responsible: {{ storage.responsible }} Responsible: {{ storage.responsible }}
</div> </div>
<span class="badge bg-primary rounded-pill">{{storage.get_total_stock_amount}}</span> <span class="badge bg-primary rounded-pill">{{storage.get_total_stock_amount}}</span>
</li> </li>
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
<nav aria-label="Storage Navigation"> {% include 'paginator.html' with paginator=storages get_param='storage_page' aria_label='Storage Page Navigation'%}
<ul class="pagination">
{% if storages.number > 1 %}
<li class="page-item"><a class="page-link" href="?storage_page={{storages.previous_page_number}}">&laquo;</a></li>
<li class="page-item"><a class="page-link" href="?storage_page={{storages.previous_page_number}}">{{storages.previous_page_number}}</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&laquo;</span></li>
{% endif %}
<li class="page-item active"><span class="page-link">{{storages.number}}</span></li>
{% if storages.paginator.num_pages > storages.number %}
<li class="page-item"><a class="page-link" href="?storage_page={{storages.next_page_number}}">{{storages.next_page_number}}</a></li>
<li class="page-item"><a class="page-link" href="?storage_page={{storages.next_page_number}}">&raquo;</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
{% endif %}
</ul>
</nav>
</div> </div>
</div> </div>
</div> </div>