Revised the code to generate the page size options in Pagination, to be clear.
This commit is contained in:
parent
e5d0feadbc
commit
bcb5da1a5e
@ -142,6 +142,7 @@ class UrlBuilder:
|
|||||||
urllib.parse.quote(self.name),
|
urllib.parse.quote(self.name),
|
||||||
urllib.parse.quote(self.value))
|
urllib.parse.quote(self.value))
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_PAGE_SIZE = 10
|
DEFAULT_PAGE_SIZE = 10
|
||||||
|
|
||||||
|
|
||||||
@ -320,10 +321,8 @@ class Pagination:
|
|||||||
def page_size_options(self):
|
def page_size_options(self):
|
||||||
base_url = UrlBuilder(self._current_url).del_param(
|
base_url = UrlBuilder(self._current_url).del_param(
|
||||||
"page").del_param("page-size")
|
"page").del_param("page-size")
|
||||||
return [self.PageSizeOption(
|
return [self.PageSizeOption(x, _page_size_url(base_url, x))
|
||||||
x, str(base_url.clone().add_param("page-size", str(x)))
|
for x in [10, 100, 200]]
|
||||||
if x != DEFAULT_PAGE_SIZE else str(base_url))
|
|
||||||
for x in [10, 100, 200]]
|
|
||||||
|
|
||||||
class PageSizeOption:
|
class PageSizeOption:
|
||||||
"""A page size option.
|
"""A page size option.
|
||||||
@ -344,6 +343,21 @@ class Pagination:
|
|||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
|
|
||||||
|
def _page_size_url(base_url, size):
|
||||||
|
"""Returns the URL for a new page size.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
base_url (UrlBuilder): The base URL builder.
|
||||||
|
size (int): The new page size.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The URL for the new page size.
|
||||||
|
"""
|
||||||
|
if size == DEFAULT_PAGE_SIZE:
|
||||||
|
return str(base_url)
|
||||||
|
return str(base_url.clone().add_param("page-size", str(size)))
|
||||||
|
|
||||||
|
|
||||||
class PageNoOutOfRangeException(Exception):
|
class PageNoOutOfRangeException(Exception):
|
||||||
"""The error thrown when the specified page number is out of
|
"""The error thrown when the specified page number is out of
|
||||||
range.
|
range.
|
||||||
|
Loading…
Reference in New Issue
Block a user