Opened 17 years ago
Closed 16 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: | dev |
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 |
Description
This truly is a tiny issue, but when subclassing Paginator, if you override page(), there are different things that can happen:
- Page number is valid, you get a Page object.
- Page number is out of range, InvalidPage is raised
- 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.
Example:
class MyPaginator(Pagintor): def page(self, number): try: super(MyPaginator, self).page(number) except InvalidPage, e: # using "number" here is problematic - it might be a string if e.number > self.num_pages: # ...
Note:
See TracTickets
for help on using tickets.
(In [7867]) Fixed #7307 -- Split InvalidPage exception into two subclasses, PageNotAnInteger and EmptyPage, for granular exception catching. Thanks for the idea, miracle2k