From 9942adac17f32a09cef77e4016627a6990ff7580 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 8 Nov 2012 16:13:23 +0100 Subject: [PATCH] Made Page class inherit collections.Sequence --- django/core/paginator.py | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/django/core/paginator.py b/django/core/paginator.py index 6b0b3542f8..6c502ae5f3 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -1,3 +1,4 @@ +import collections from math import ceil class InvalidPage(Exception): @@ -75,7 +76,7 @@ class Paginator(object): 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 @@ class Page(object): # 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