Opened 10 years ago

Closed 10 years ago

#7307 closed (fixed)

Pagination: Give the InvalidPage exception an attribute storing the converted integer number

Reported by: miracle2k Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This truly is a tiny issue, but when subclassing Paginator, if you override page(), there are different things that can happen:

  1. Page number is valid, you get a Page object.
  2. Page number is out of range, InvalidPage is raised
  3. Page number is not a number, InvalidPage is raised

In your child class, you cannot differ between 1) and 2/3), so if you want to work with "number" afterwards, you once again need to check it's an int, and raise the appropriate exceptions if not.

Suggestioned solution: Give the InvalidPage exception a number field that is set whenever the number was successfully converted to an integer.


class MyPaginator(Pagintor):
   def page(self, number):
          super(MyPaginator, self).page(number)
      except InvalidPage, e:
          # using "number" here is problematic - it might be a string
          if e.number > self.num_pages:
             # ...

Change History (1)

comment:1 Changed 10 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [7867]) Fixed #7307 -- Split InvalidPage exception into two subclasses, PageNotAnInteger and EmptyPage, for granular exception catching. Thanks for the idea, miracle2k

Note: See TracTickets for help on using tickets.
Back to Top