If a user asks for a page beyond the range of pages, an EmptyPage
exception is thrown. Catch this and clamp the page number
appropriately.

Reported-by: Jeremy Kerr <j...@ozlabs.org>
Signed-off-by: Daniel Axtens <d...@axtens.net>
---
 patchwork/paginator.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/patchwork/paginator.py b/patchwork/paginator.py
index 609e908c2cbf..e4cf556ebd96 100644
--- a/patchwork/paginator.py
+++ b/patchwork/paginator.py
@@ -55,6 +55,12 @@ class Paginator(paginator.Paginator):
         except ValueError:
             page_no = 1
             self.current_page = self.page(page_no)
+        except paginator.EmptyPage:
+            if page_no < 1:
+                page_no = 1
+            else:
+                page_no = self.num_pages
+            self.current_page = self.page(page_no)
 
         self.leading_set = self.trailing_set = []
 
-- 
2.11.0

_______________________________________________
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to