[PATCH] Handle EmptyPage exceptions

Daniel Axtens dja at axtens.net
Mon Aug 28 14:11:27 AEST 2017


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 at ozlabs.org>
Signed-off-by: Daniel Axtens <dja at 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



More information about the Patchwork mailing list