From: Daniel Axtens Date: Mon, 28 Aug 2017 04:11:27 +0000 (+1000) Subject: Handle EmptyPage exceptions X-Git-Tag: v2.0.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ac9ed5f2e64cf14bee8749d4994e8140885a797;p=thirdparty%2Fpatchwork.git 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 (cherry picked from commit 0901378a0aa32fbd9c0e6a937219199dab759ce0) --- 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 = []