Renamed the is_needed property to is_paged in the Pagination utility.
This commit is contained in:
parent
511328a0bd
commit
8be44ccf5f
@ -19,7 +19,7 @@ pagination.html: The pagination navigation bar.
|
|||||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||||
First written: 2023/1/26
|
First written: 2023/1/26
|
||||||
#}
|
#}
|
||||||
{% if pagination.is_needed %}
|
{% if pagination.is_paged %}
|
||||||
<nav aria-label="Page navigation">
|
<nav aria-label="Page navigation">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{% for link in pagination.page_links %}
|
{% for link in pagination.page_links %}
|
||||||
|
@ -88,7 +88,7 @@ class Pagination(t.Generic[T]):
|
|||||||
self.__total_pages: int = 0 if len(items) == 0 \
|
self.__total_pages: int = 0 if len(items) == 0 \
|
||||||
else int((len(items) - 1) / self.page_size) + 1
|
else int((len(items) - 1) / self.page_size) + 1
|
||||||
"""The total number of pages."""
|
"""The total number of pages."""
|
||||||
self.is_needed: bool = self.__total_pages > 1
|
self.is_paged: bool = self.__total_pages > 1
|
||||||
"""Whether there should be pagination."""
|
"""Whether there should be pagination."""
|
||||||
self.__default_page_no: int = 0
|
self.__default_page_no: int = 0
|
||||||
"""The default page number."""
|
"""The default page number."""
|
||||||
|
@ -127,18 +127,18 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
"""The testing parameters."""
|
"""The testing parameters."""
|
||||||
|
|
||||||
def __init__(self, items: list[int], is_reversed: bool | None,
|
def __init__(self, items: list[int], is_reversed: bool | None,
|
||||||
result: list[int], is_needed: bool):
|
result: list[int], is_paged: bool):
|
||||||
"""Constructs the expected pagination.
|
"""Constructs the expected pagination.
|
||||||
|
|
||||||
:param items: All the items in the list.
|
:param items: All the items in the list.
|
||||||
:param is_reversed: Whether the default page is the last page.
|
:param is_reversed: Whether the default page is the last page.
|
||||||
:param result: The expected items on the page.
|
:param result: The expected items on the page.
|
||||||
:param is_needed: Whether the pagination is needed.
|
:param is_paged: Whether the pagination is needed.
|
||||||
"""
|
"""
|
||||||
self.items: list[int] = items
|
self.items: list[int] = items
|
||||||
self.is_reversed: bool | None = is_reversed
|
self.is_reversed: bool | None = is_reversed
|
||||||
self.result: list[int] = result
|
self.result: list[int] = result
|
||||||
self.is_needed: bool = is_needed
|
self.is_paged: bool = is_paged
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
"""Sets up the test.
|
"""Sets up the test.
|
||||||
@ -158,7 +158,7 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
is_reversed=self.params.is_reversed)
|
is_reversed=self.params.is_reversed)
|
||||||
else:
|
else:
|
||||||
pagination = Pagination(self.params.items)
|
pagination = Pagination(self.params.items)
|
||||||
self.assertEqual(pagination.is_needed, self.params.is_needed)
|
self.assertEqual(pagination.is_paged, self.params.is_paged)
|
||||||
self.assertEqual(pagination.list, self.params.result)
|
self.assertEqual(pagination.list, self.params.result)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -166,14 +166,14 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
self.client.headers["Referer"] = "https://testserver"
|
self.client.headers["Referer"] = "https://testserver"
|
||||||
|
|
||||||
def __test_success(self, query: str, items: range,
|
def __test_success(self, query: str, items: range,
|
||||||
result: range, is_needed: bool = True,
|
result: range, is_paged: bool = True,
|
||||||
is_reversed: bool | None = None) -> None:
|
is_reversed: bool | None = None) -> None:
|
||||||
"""Tests the pagination.
|
"""Tests the pagination.
|
||||||
|
|
||||||
:param query: The query string.
|
:param query: The query string.
|
||||||
:param items: The original items.
|
:param items: The original items.
|
||||||
:param result: The expected page content.
|
:param result: The expected page content.
|
||||||
:param is_needed: Whether the pagination is needed.
|
:param is_paged: Whether the pagination is needed.
|
||||||
:param is_reversed: Whether the list is reversed.
|
:param is_reversed: Whether the list is reversed.
|
||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
@ -181,7 +181,7 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
if query != "":
|
if query != "":
|
||||||
target = f"{target}?{query}"
|
target = f"{target}?{query}"
|
||||||
self.params = self.Params(list(items), is_reversed,
|
self.params = self.Params(list(items), is_reversed,
|
||||||
list(result), is_needed)
|
list(result), is_paged)
|
||||||
response: httpx.Response = self.client.get(target)
|
response: httpx.Response = self.client.get(target)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@ -234,12 +234,12 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
# Empty list
|
# Empty list
|
||||||
self.__test_success("", range(0, 0), range(0, 0), is_needed=False)
|
self.__test_success("", range(0, 0), range(0, 0), is_paged=False)
|
||||||
# A list that fits in one page
|
# A list that fits in one page
|
||||||
self.__test_success("", range(1, 4), range(1, 4), is_needed=False)
|
self.__test_success("", range(1, 4), range(1, 4), is_paged=False)
|
||||||
# A large page size that fits in everything
|
# A large page size that fits in everything
|
||||||
self.__test_success("page-size=1000", range(1, 687), range(1, 687),
|
self.__test_success("page-size=1000", range(1, 687), range(1, 687),
|
||||||
is_needed=False)
|
is_paged=False)
|
||||||
|
|
||||||
def test_reversed(self) -> None:
|
def test_reversed(self) -> None:
|
||||||
"""Tests the default page on a reversed list.
|
"""Tests the default page on a reversed list.
|
||||||
|
Loading…
Reference in New Issue
Block a user