Renamed the page_links and page_sizes properties to pages and page_size_options in the Pagination utility.

This commit is contained in:
依瑪貓 2023-02-04 12:51:30 +08:00
parent fd63149066
commit 16b2eb1c93
2 changed files with 19 additions and 19 deletions

View File

@ -22,7 +22,7 @@ First written: 2023/1/26
{% if pagination.is_paged %}
<nav aria-label="Page navigation">
<ul class="pagination">
{% for link in pagination.page_links %}
{% for link in pagination.pages %}
{% if link.uri is none %}
<li class="page-item disabled {% if not link.is_for_mobile %} d-none d-md-inline {% endif %}">
<span class="page-link">
@ -42,7 +42,7 @@ First written: 2023/1/26
{{ pagination.page_size }}
</div>
<ul class="dropdown-menu">
{% for link in pagination.page_sizes %}
{% for link in pagination.page_size_options %}
<li>
<a class="dropdown-item {% if link.is_current %} active {% endif %}" href="{{ link.uri }}">
{{ link.text }}

View File

@ -84,10 +84,10 @@ class Pagination(t.Generic[T]):
"""Whether there should be pagination."""
self.list: list[T] = pagination.list
"""The items shown in the list"""
self.page_links: list[Link] = pagination.page_links
"""The pagination links."""
self.page_sizes: list[Link] = pagination.page_sizes
"""The links to switch the number of items in a page."""
self.pages: list[Link] = pagination.pages
"""The pages."""
self.page_size_options: list[Link] = pagination.page_size_options
"""The options to the number of items in a page."""
class AbstractPagination(t.Generic[T]):
@ -99,10 +99,10 @@ class AbstractPagination(t.Generic[T]):
"""Whether there should be pagination."""
self.list: list[T] = []
"""The items shown in the list"""
self.page_links: list[Link] = []
"""The pagination links."""
self.page_sizes: list[Link] = []
"""The links to switch the number of items in a page."""
self.pages: list[Link] = []
"""The pages."""
self.page_size_options: list[Link] = []
"""The options to the number of items in a page."""
class EmptyPagination(AbstractPagination[T]):
@ -112,8 +112,8 @@ class EmptyPagination(AbstractPagination[T]):
class NonEmptyPagination(AbstractPagination[T]):
"""The pagination with real data."""
AVAILABLE_PAGE_SIZES: list[int] = [10, 100, 200]
"""The available page sizes."""
PAGE_SIZE_OPTIONS: list[int] = [10, 100, 200]
"""The page size options."""
def __init__(self, items: list[T], is_reversed: bool = False):
"""Constructs the pagination.
@ -144,8 +144,8 @@ class NonEmptyPagination(AbstractPagination[T]):
if upper_bound > len(items):
upper_bound = len(items)
self.list = items[lower_bound:upper_bound]
self.page_links = self.__get_page_links()
self.page_sizes = self.__get_page_sizes()
self.pages = self.__get_pages()
self.page_size_options = self.__get_page_size_options()
def __get_page_size(self) -> int:
"""Returns the page size.
@ -188,7 +188,7 @@ class NonEmptyPagination(AbstractPagination[T]):
str(self.__total_pages)))
return page_no
def __get_page_links(self) -> list[Link]:
def __get_pages(self) -> list[Link]:
"""Returns the page links in the pagination navigation.
:return: The page links in the pagination navigation.
@ -265,16 +265,16 @@ class NonEmptyPagination(AbstractPagination[T]):
return self.__uri_set("page-no", None)
return self.__uri_set("page-no", str(page_no))
def __get_page_sizes(self) -> list[Link]:
"""Returns the available page sizes.
def __get_page_size_options(self) -> list[Link]:
"""Returns the page size options.
:return: The available page sizes.
:return: The page size options.
"""
if not self.is_paged:
return []
return [Link(str(x), self.__uri_size(x),
is_current=x == self.__page_size)
for x in self.AVAILABLE_PAGE_SIZES]
for x in self.PAGE_SIZE_OPTIONS]
def __uri_size(self, page_size: int) -> str:
"""Returns the URI of a page size.