Django

Code

Ticket #7307 (closed: fixed)

Opened 3 months ago

Last modified 2 months ago

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

Reported by: miracle2k Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation:
Needs tests: Patch needs improvement:

Description

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.

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

Attachments

Change History

07/07/08 21:20:49 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #7307 (Pagination: Give the InvalidPage exception an attribute storing the converted integer number)




Change Properties
Action