diff mbox series

Handle EmptyPage exceptions

Message ID 20170828041127.20127-1-dja@axtens.net
State Accepted
Headers show
Series Handle EmptyPage exceptions | expand

Commit Message

Daniel Axtens Aug. 28, 2017, 4:11 a.m. UTC
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>
---
 patchwork/paginator.py | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Jeremy Kerr Aug. 28, 2017, 4:21 a.m. UTC | #1
Hi Daniel,

> 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.

This does fix the issue I'm seeing, thanks!

Tested-by: Jeremy Kerr <jk@ozlabs.org>

Cheers,


Jeremy
Stephen Finucane Aug. 28, 2017, 8:12 a.m. UTC | #2
On Mon, 2017-08-28 at 14:11 +1000, Daniel Axtens wrote:
> 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>

Reviewed-by: Stephen Finucane <stephen@that.guru>

...and applied.
diff mbox series

Patch

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 = []