diff --git a/django/core/paginator.py b/django/core/paginator.py
index 8b4d289..6b0b354 100644
a
|
b
|
class Page(object):
|
132 | 132 | return self.has_previous() or self.has_next() |
133 | 133 | |
134 | 134 | def next_page_number(self): |
135 | | return self.number + 1 |
| 135 | return self.paginator.validate_number(self.number + 1) |
136 | 136 | |
137 | 137 | def previous_page_number(self): |
138 | | return self.number - 1 |
| 138 | return self.paginator.validate_number(self.number - 1) |
139 | 139 | |
140 | 140 | def start_index(self): |
141 | 141 | """ |
diff --git a/docs/topics/pagination.txt b/docs/topics/pagination.txt
index 566319f..e00be31 100644
a
|
b
|
Methods
|
253 | 253 | |
254 | 254 | .. method:: Page.next_page_number() |
255 | 255 | |
256 | | Returns the next page number. Note that this is "dumb" and will return the |
257 | | next page number regardless of whether a subsequent page exists. |
| 256 | Returns the next page number. |
| 257 | Raises :exc:`InvalidPage` if next page doesn't exist. |
258 | 258 | |
259 | 259 | .. method:: Page.previous_page_number() |
260 | 260 | |
261 | | Returns the previous page number. Note that this is "dumb" and will return |
262 | | the previous page number regardless of whether a previous page exists. |
| 261 | Returns the previous page number. |
| 262 | Raises :exc:`InvalidPage` if previous page doesn't exist. |
263 | 263 | |
264 | 264 | .. method:: Page.start_index() |
265 | 265 | |
diff --git a/tests/modeltests/pagination/tests.py b/tests/modeltests/pagination/tests.py
index b7e217e..57cd3b4 100644
a
|
b
|
class PaginationTests(TestCase):
|
45 | 45 | self.assertFalse(p.has_previous()) |
46 | 46 | self.assertTrue(p.has_other_pages()) |
47 | 47 | self.assertEqual(2, p.next_page_number()) |
48 | | self.assertEqual(0, p.previous_page_number()) |
| 48 | self.assertRaises(InvalidPage, p.previous_page_number) |
49 | 49 | self.assertEqual(1, p.start_index()) |
50 | 50 | self.assertEqual(5, p.end_index()) |
51 | 51 | |
… |
… |
class PaginationTests(TestCase):
|
63 | 63 | self.assertFalse(p.has_next()) |
64 | 64 | self.assertTrue(p.has_previous()) |
65 | 65 | self.assertTrue(p.has_other_pages()) |
66 | | self.assertEqual(3, p.next_page_number()) |
| 66 | self.assertRaises(InvalidPage, p.next_page_number) |
67 | 67 | self.assertEqual(1, p.previous_page_number()) |
68 | 68 | self.assertEqual(6, p.start_index()) |
69 | 69 | self.assertEqual(9, p.end_index()) |
… |
… |
class PaginationTests(TestCase):
|
104 | 104 | |
105 | 105 | def test_paginate_list(self): |
106 | 106 | # Paginators work with regular lists/tuples, too -- not just with QuerySets. |
107 | | paginator = Paginator([1, 2, 3, 4, 5, 6, 7, 8, 9], 5) |
| 107 | paginator = Paginator([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) |
108 | 108 | self.assertEqual(9, paginator.count) |
109 | | self.assertEqual(2, paginator.num_pages) |
110 | | self.assertEqual([1, 2], paginator.page_range) |
111 | | p = paginator.page(1) |
112 | | self.assertEqual(u"<Page 1 of 2>", unicode(p)) |
113 | | self.assertEqual([1, 2, 3, 4, 5], p.object_list) |
| 109 | self.assertEqual(3, paginator.num_pages) |
| 110 | self.assertEqual([1, 2, 3], paginator.page_range) |
| 111 | p = paginator.page(2) |
| 112 | self.assertEqual(u"<Page 2 of 3>", unicode(p)) |
| 113 | self.assertEqual([4, 5, 6], p.object_list) |
114 | 114 | self.assertTrue(p.has_next()) |
115 | | self.assertFalse(p.has_previous()) |
| 115 | self.assertTrue(p.has_previous()) |
116 | 116 | self.assertTrue(p.has_other_pages()) |
117 | | self.assertEqual(2, p.next_page_number()) |
118 | | self.assertEqual(0, p.previous_page_number()) |
119 | | self.assertEqual(1, p.start_index()) |
120 | | self.assertEqual(5, p.end_index()) |
| 117 | self.assertEqual(1, p.previous_page_number()) |
| 118 | self.assertEqual(3, p.next_page_number()) |
| 119 | self.assertEqual(4, p.start_index()) |
| 120 | self.assertEqual(6, p.end_index()) |
121 | 121 | |
122 | 122 | def test_paginate_misc_classes(self): |
123 | 123 | # Paginator can be passed other objects with a count() method. |