Revised Pagination so that the status ID does not pass along with the pagination links in the Mia core application.
This commit is contained in:
parent
97b9190b32
commit
474c74ebb0
@ -272,7 +272,7 @@ class Pagination:
|
|||||||
PaginationException: With invalid pagination parameters
|
PaginationException: With invalid pagination parameters
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
current_url (str): The current request URL.
|
current_url (UrlBuilder): The current request URL.
|
||||||
is_reversed (bool): Whether we should display the last page first.
|
is_reversed (bool): Whether we should display the last page first.
|
||||||
page_size (int): The page size.
|
page_size (int): The page size.
|
||||||
total_pages (int): The total number of pages available.
|
total_pages (int): The total number of pages available.
|
||||||
@ -283,7 +283,7 @@ class Pagination:
|
|||||||
DEFAULT_PAGE_SIZE = 10
|
DEFAULT_PAGE_SIZE = 10
|
||||||
|
|
||||||
def __init__(self, request, items, is_reversed=False):
|
def __init__(self, request, items, is_reversed=False):
|
||||||
self.current_url = request.get_full_path()
|
self.current_url = UrlBuilder(request.get_full_path())
|
||||||
self.is_reversed = is_reversed
|
self.is_reversed = is_reversed
|
||||||
self.page_size = self.DEFAULT_PAGE_SIZE
|
self.page_size = self.DEFAULT_PAGE_SIZE
|
||||||
self.total_pages = None
|
self.total_pages = None
|
||||||
@ -295,16 +295,13 @@ class Pagination:
|
|||||||
try:
|
try:
|
||||||
self.page_size = int(request.GET["page-size"])
|
self.page_size = int(request.GET["page-size"])
|
||||||
if self.page_size == self.DEFAULT_PAGE_SIZE:
|
if self.page_size == self.DEFAULT_PAGE_SIZE:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page-size"))
|
||||||
UrlBuilder(self.current_url).remove("page-size")))
|
|
||||||
if self.page_size < 1:
|
if self.page_size < 1:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page-size"))
|
||||||
UrlBuilder(self.current_url).remove("page-size")))
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.page_size = self.DEFAULT_PAGE_SIZE
|
self.page_size = self.DEFAULT_PAGE_SIZE
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page-size"))
|
||||||
UrlBuilder(self.current_url).remove("page-size")))
|
|
||||||
self.total_pages = int(
|
self.total_pages = int(
|
||||||
(len(items) - 1) / self.page_size) + 1
|
(len(items) - 1) / self.page_size) + 1
|
||||||
default_page_no = 1 if not is_reversed else self.total_pages
|
default_page_no = 1 if not is_reversed else self.total_pages
|
||||||
@ -314,22 +311,17 @@ class Pagination:
|
|||||||
try:
|
try:
|
||||||
self.page_no = int(request.GET["page"])
|
self.page_no = int(request.GET["page"])
|
||||||
if not self.is_paged:
|
if not self.is_paged:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page"))
|
||||||
UrlBuilder(self.current_url).remove("page")))
|
|
||||||
if self.page_no == default_page_no:
|
if self.page_no == default_page_no:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page"))
|
||||||
UrlBuilder(self.current_url).remove("page")))
|
|
||||||
if self.page_no < 1:
|
if self.page_no < 1:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page"))
|
||||||
UrlBuilder(self.current_url).remove("page")))
|
|
||||||
if self.page_no > self.total_pages:
|
if self.page_no > self.total_pages:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page"))
|
||||||
UrlBuilder(self.current_url).remove("page")))
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.page_no = default_page_no
|
self.page_no = default_page_no
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise PaginationException(str(
|
raise PaginationException(self.current_url.remove("page"))
|
||||||
UrlBuilder(self.current_url).remove("page")))
|
|
||||||
|
|
||||||
if not self.is_paged:
|
if not self.is_paged:
|
||||||
self.page_no = 1
|
self.page_no = 1
|
||||||
@ -344,7 +336,7 @@ class Pagination:
|
|||||||
Returns:
|
Returns:
|
||||||
list[Link]: The navigation links of the pagination bar.
|
list[Link]: The navigation links of the pagination bar.
|
||||||
"""
|
"""
|
||||||
base_url = UrlBuilder(self.current_url).remove("page")
|
base_url = self.current_url.clone().remove("page").remove("s")
|
||||||
links = []
|
links = []
|
||||||
# The previous page
|
# The previous page
|
||||||
link = self.Link()
|
link = self.Link()
|
||||||
@ -453,8 +445,7 @@ class Pagination:
|
|||||||
Returns:
|
Returns:
|
||||||
list[PageSizeOption]: The page size options.
|
list[PageSizeOption]: The page size options.
|
||||||
"""
|
"""
|
||||||
base_url = UrlBuilder(self.current_url).remove(
|
base_url = self.current_url.remove("page").remove("page-size")
|
||||||
"page").remove("page-size")
|
|
||||||
return [self.PageSizeOption(x, self._page_size_url(base_url, x))
|
return [self.PageSizeOption(x, self._page_size_url(base_url, x))
|
||||||
for x in [10, 100, 200]]
|
for x in [10, 100, 200]]
|
||||||
|
|
||||||
@ -493,10 +484,10 @@ class PaginationException(Exception):
|
|||||||
"""The exception thrown with invalid pagination parameters.
|
"""The exception thrown with invalid pagination parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url (str): The canonical URL to redirect to.
|
url_builder (UrlBuilder): The canonical URL to redirect to.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
url (str): The canonical URL to redirect to.
|
url (str): The canonical URL to redirect to.
|
||||||
"""
|
"""
|
||||||
def __init__(self, url):
|
def __init__(self, url_builder):
|
||||||
self.url = url
|
self.url = str(url_builder)
|
||||||
|
Loading…
Reference in New Issue
Block a user