From 3abce4498f4598c9031bdeea1457ec1145c4da66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 2 Jul 2020 00:42:34 +0800 Subject: [PATCH] Revised the pagination to redirect to the URL without the page number if the specific page number is exactly the default page number. That is, the page number is totally unnecessary. --- accounting/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/accounting/utils.py b/accounting/utils.py index df5139f..16fc838 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -66,9 +66,12 @@ class Pagination: if page_size is not None \ else self.DEFAULT_PAGE_SIZE total_pages = int((count - 1) / self.page_size) + 1 + default_page = 1 if not is_reverse else total_pages + if page_no == default_page: + raise PageNoOutOfRangeError() self.page_no = page_no \ if page_no is not None \ - else 1 if not is_reverse else total_pages + else default_page if self.page_no > total_pages: raise PageNoOutOfRangeError()