Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made Page class inherit collections.Sequence

  • Loading branch information...
commit 9942adac17f32a09cef77e4016627a6990ff7580 1 parent 45802e1
@claudep claudep authored
Showing with 2 additions and 31 deletions.
  1. +2 −31 django/core/paginator.py
View
33 django/core/paginator.py
@@ -1,3 +1,4 @@
+import collections
from math import ceil
class InvalidPage(Exception):
@@ -75,7 +76,7 @@ def _get_page_range(self):
QuerySetPaginator = Paginator # For backwards-compatibility.
-class Page(object):
+class Page(collections.Sequence):
def __init__(self, object_list, number, paginator):
self.object_list = object_list
self.number = number
@@ -92,36 +93,6 @@ def __getitem__(self, index):
# it won't be a database hit per __getitem__.
return list(self.object_list)[index]
- # The following four methods are only necessary for Python <2.6
- # compatibility (this class could just extend 2.6's collections.Sequence).
-
- def __iter__(self):
- i = 0
- try:
- while True:
- v = self[i]
- yield v
- i += 1
- except IndexError:
- return
-
- def __contains__(self, value):
- for v in self:
- if v == value:
- return True
- return False
-
- def index(self, value):
- for i, v in enumerate(self):
- if v == value:
- return i
- raise ValueError
-
- def count(self, value):
- return sum([1 for v in self if v == value])
-
- # End of compatibility methods.
-
def has_next(self):
return self.number < self.paginator.num_pages
Please sign in to comment.
Something went wrong with that request. Please try again.