generalize usage of the paginate_jinja macro

This commit is contained in:
thomas girod 2024-09-25 14:35:13 +02:00
parent 6449724ed5
commit 1800785b80
11 changed files with 25 additions and 15 deletions

View File

@ -53,6 +53,7 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{# TODO: Replace this pagination by an Alpine pagination #}
<script type="text/javascript"> <script type="text/javascript">
function formPagination(link){ function formPagination(link){
$("form").attr("action", link.href); $("form").attr("action", link.href);

View File

@ -11,6 +11,7 @@
<link rel="stylesheet" href="{{ scss('core/markdown.scss') }}"> <link rel="stylesheet" href="{{ scss('core/markdown.scss') }}">
<link rel="stylesheet" href="{{ scss('core/header.scss') }}"> <link rel="stylesheet" href="{{ scss('core/header.scss') }}">
<link rel="stylesheet" href="{{ scss('core/navbar.scss') }}"> <link rel="stylesheet" href="{{ scss('core/navbar.scss') }}">
<link rel="stylesheet" href="{{ scss('core/pagination.scss') }}">
<link rel="stylesheet" href="{{ static('vendored/select2/select2.min.css') }}"> <link rel="stylesheet" href="{{ static('vendored/select2/select2.min.css') }}">
{% block jquery_css %} {% block jquery_css %}

View File

@ -157,6 +157,15 @@
{% endmacro %} {% endmacro %}
{% macro paginate_jinja(current_page, paginator) %} {% macro paginate_jinja(current_page, paginator) %}
{# Add pagination buttons for pages without Alpine.
This must be coupled with a view that handles pagination
with the Django Paginator object.
Parameters:
current_page (django.core.paginator.Page): the current page object
paginator (django.core.paginator.Paginator): the paginator object
#}
<nav class="pagination"> <nav class="pagination">
{% if current_page.has_previous() %} {% if current_page.has_previous() %}
<a href="?page={{ current_page.previous_page_number() }}"> <a href="?page={{ current_page.previous_page_number() }}">
@ -170,8 +179,8 @@
{% for i in paginator.get_elided_page_range(current_page.number) %} {% for i in paginator.get_elided_page_range(current_page.number) %}
{% if i == current_page.number %} {% if i == current_page.number %}
<button class="active">{{ i }}</button> <button class="active">{{ i }}</button>
{% elif i == paginator.ELLIPSIS %} {% elif i == paginator.ELLIPSIS %}
<strong>{{ paginator.ELLIPSIS }}</strong> <strong>{{ paginator.ELLIPSIS }}</strong>
{% else %} {% else %}
<a href="?page={{ i }}"> <a href="?page={{ i }}">
<button>{{ i }}</button> <button>{{ i }}</button>

View File

@ -1,5 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link, paginate %} {% from 'core/macros.jinja' import user_profile_link, paginate_jinja %}
{% block title %} {% block title %}
{% trans %}Cash register summary list{% endtrans %} {% trans %}Cash register summary list{% endtrans %}
@ -57,7 +57,7 @@
</table> </table>
<br> <br>
{% if is_paginated %} {% if is_paginated %}
{{ paginate(page_obj, paginator) }} {{ paginate_jinja(page_obj, paginator) }}
{% endif %} {% endif %}
{% else %} {% else %}
{% trans %}There is no cash register summary in this website.{% endtrans %} {% trans %}There is no cash register summary in this website.{% endtrans %}

View File

@ -1,5 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import paginate %} {% from "core/macros.jinja" import paginate_jinja %}
{% block title %} {% block title %}
{%- trans %}Reloads list{% endtrans %} -- {{ counter.name }} {%- trans %}Reloads list{% endtrans %} -- {{ counter.name }}
@ -28,7 +28,7 @@
{%- endfor %} {%- endfor %}
</table> </table>
{% if is_paginated %} {% if is_paginated %}
{{ paginate(page_obj, paginator) }} {{ paginate_jinja(page_obj, paginator) }}
{% endif %} {% endif %}
{%- endblock %} {%- endblock %}

View File

@ -1,5 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import paginate %} {% from "core/macros.jinja" import paginate_jinja %}
{% block title %} {% block title %}
{%- trans %}Election list{% endtrans %} {%- trans %}Election list{% endtrans %}
@ -46,7 +46,7 @@
</section> </section>
{%- endfor %} {%- endfor %}
{% if is_paginated %} {% if is_paginated %}
{{ paginate(page_obj, paginator) }} {{ paginate_jinja(page_obj, paginator) }}
{% endif %} {% endif %}
{%- endblock %} {%- endblock %}

View File

@ -10,7 +10,6 @@
{% block additional_css %} {% block additional_css %}
<link rel="stylesheet" href="{{ scss('forum/css/forum.scss') }}"> <link rel="stylesheet" href="{{ scss('forum/css/forum.scss') }}">
<link rel="stylesheet" href="{{ scss('core/pagination.scss') }}">
{% endblock %} {% endblock %}
{% block content %} {% block content %}

View File

@ -1,5 +1,5 @@
{% from "core/macros.jinja" import user_mini_profile, paginate %}
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from "core/macros.jinja" import user_mini_profile, paginate_jinja %}
{% block title %} {% block title %}
{% trans %}Search user{% endtrans %} {% trans %}Search user{% endtrans %}
@ -18,7 +18,9 @@
{% endfor %} {% endfor %}
</div> </div>
{{ paginate(page_obj, paginator) }} {% if page_obj.has_other_pages() %}
{{ paginate_jinja(page_obj, paginator) }}
{% endif %}
<hr> <hr>
{% endif %} {% endif %}
<h2>{% trans %}Search user{% endtrans %}</h2> <h2>{% trans %}Search user{% endtrans %}</h2>

View File

@ -7,7 +7,6 @@
{% block additional_css %} {% block additional_css %}
<link rel="stylesheet" href="{{ scss('pedagogy/css/pedagogy.scss') }}"> <link rel="stylesheet" href="{{ scss('pedagogy/css/pedagogy.scss') }}">
<link rel="stylesheet" href="{{ scss('core/pagination.scss') }}">
{% endblock %} {% endblock %}
{% block head %} {% block head %}

View File

@ -1,5 +1,5 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import paginate %} {% from "core/macros.jinja" import paginate_jinja %}
{% block title %} {% block title %}
{% trans %}Operation logs{% endtrans %} {% trans %}Operation logs{% endtrans %}
@ -28,5 +28,5 @@
</table> </table>
<br> <br>
{{ paginate(page_obj, paginator) }} {{ paginate_jinja(page_obj, paginator) }}
{% endblock content %} {% endblock content %}

View File

@ -3,7 +3,6 @@
{%- block additional_css -%} {%- block additional_css -%}
<link rel="stylesheet" href="{{ scss('sas/css/album.scss') }}"> <link rel="stylesheet" href="{{ scss('sas/css/album.scss') }}">
<link rel="stylesheet" href="{{ scss('core/pagination.scss') }}">
{%- endblock -%} {%- endblock -%}
{% block title %} {% block title %}