diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-11-08 16:13:23 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-11-08 16:13:23 +0100 |
| commit | 9942adac17f32a09cef77e4016627a6990ff7580 (patch) | |
| tree | a2681039e1852c30c68949e0c8de07b14352db16 | |
| parent | 45802e12481e86f7b9c1f392a54b9d25671214d9 (diff) | |
Made Page class inherit collections.Sequence
| -rw-r--r-- | django/core/paginator.py | 33 |
1 files 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 |
