]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Handle EmptyPage exceptions
authorDaniel Axtens <dja@axtens.net>
Mon, 28 Aug 2017 04:11:27 +0000 (14:11 +1000)
committerStephen Finucane <stephen@that.guru>
Mon, 28 Aug 2017 08:12:15 +0000 (09:12 +0100)
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 <jk@ozlabs.org>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Tested-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/paginator.py

index 609e908c2cbf55d1687b6e69065f2cba033e5a81..e4cf556ebd96ca602dccbb242c567e2fb09b9cb5 100644 (file)
@@ -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 = []