pytilpack.paginator¶
pytilpack.paginator
¶
ページネーション用ユーティリティ。
Paginator(page, per_page, items, total)
¶
ページング用の簡易ヘルパ。
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
page
|
int
|
1オリジンのページ番号 |
必須 |
per_page
|
int
|
1ページあたりのアイテム数 |
必須 |
items
|
list[T]
|
現在のページのデータ |
必須 |
total
|
int
|
全データ件数 |
必須 |
例::
{% macro render_pagination(endpoint, paginator, **kwargs) %}
<nav>
<ul class="pagination justify-content-center">
<li class="page-item{% if not paginator.has_prev %} disabled{% endif %}">
<a class="page-link" href="{{ url_for(endpoint, page=paginator.prev_num, **kwargs) }}"><</a>
</li>
{% for page in paginator.iter_pages() %}
{% if page is none %}
<li class="page-item disabled">...</li>
{% else %}
<li class="page-item{% if paginator.page == page %} active{% endif %}">
<a class="page-link" href="{{ url_for(endpoint, page=page, **kwargs) }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
<li class="page-item{% if not paginator.has_next %} disabled{% endif %}">
<a class="page-link" href="{{ url_for(endpoint, page=paginator.next_num, **kwargs) }}">></a>
</li>
</ul>
</nav>
{% endmacro %}
ソースコード位置: pytilpack/paginator.py
pages
property
¶
ページ数。
has_prev
property
¶
前ページがあるか否か。
has_next
property
¶
次ページがあるか否か。
prev_num
property
¶
前ページのページ番号。
next_num
property
¶
次ページのページ番号。
next()
¶
次ページのPaginatorオブジェクト。
prev()
¶
前ページのPaginatorオブジェクト。
iter_pages(left_edge=2, left_current=2, right_current=4, right_edge=2)
¶
ページネーションウィジェット用のページ番号を生成する。
ページの先頭と末尾の間でスキップされるページは None で表現する。 例えば、総ページ数が 20 ページで現在のページが 7 ページの場合、以下の値が生成される。 1, 2, None, 5, 6, 7, 8, 9, 10, 11, None, 19, 20
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
left_edge
|
int
|
最初のページから表示するページ数。 |
2
|
left_current
|
int
|
現在のページの左側に表示されるページ数。 |
2
|
right_current
|
int
|
現在のページの右側に表示されるページ数。 |
4
|
right_edge
|
int
|
最後のページから表示するページ数。 |
2
|
戻り値:
| タイプ | デスクリプション |
|---|---|
list[int | None]
|
ページ番号のリスト。ページ番号が連続していない場合はNoneを挟む。 |