From 0901378a0aa32fbd9c0e6a937219199dab759ce0 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Mon, 28 Aug 2017 14:11:27 +1000 Subject: [PATCH] Handle EmptyPage exceptions 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 Signed-off-by: Daniel Axtens Tested-by: Jeremy Kerr Reviewed-by: Stephen Finucane --- patchwork/paginator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/patchwork/paginator.py b/patchwork/paginator.py index 609e908c..e4cf556e 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.47.3