Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'stable/1.5.x' of https://github.com/django/django into …

…stable/1.5.x
  • Loading branch information...
commit d35b95c2f45bc5bc91deab12e503b04126fe70d7 2 parents d828d4e + b85cb92
authored November 04, 2012
7  django/views/generic/list.py
@@ -50,9 +50,10 @@ def paginate_queryset(self, queryset, page_size):
50 50
         try:
51 51
             page = paginator.page(page_number)
52 52
             return (paginator, page, page.object_list, page.has_other_pages())
53  
-        except InvalidPage:
54  
-            raise Http404(_('Invalid page (%(page_number)s)') % {
55  
-                                'page_number': page_number
  53
+        except InvalidPage as e:
  54
+            raise Http404(_('Invalid page (%(page_number)s): %(message)s') % {
  55
+                                'page_number': page_number,
  56
+                                'message': e.message,
56 57
             })
57 58
 
58 59
     def get_paginate_by(self, queryset):
12  tests/regressiontests/generic_views/list.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 from django.core.exceptions import ImproperlyConfigured
4 4
 from django.test import TestCase
  5
+from django.test.utils import override_settings
5 6
 from django.views.generic.base import View
6 7
 
7 8
 from .models import Author, Artist
@@ -171,8 +172,17 @@ def test_paginated_list_view_does_not_load_entire_table(self):
171 172
         with self.assertNumQueries(3):
172 173
             self.client.get('/list/authors/notempty/paginated/')
173 174
 
  175
+    @override_settings(DEBUG=True)
  176
+    def test_paginated_list_view_returns_useful_message_on_invalid_page(self):
  177
+        # test for #19240
  178
+        # tests that source exception's message is included in page
  179
+        self._make_authors(1)
  180
+        res = self.client.get('/list/authors/paginated/2/')
  181
+        self.assertEqual(res.status_code, 404)
  182
+        self.assertEqual(res.context.get('reason'),
  183
+                "Invalid page (2): That page contains no results")
  184
+
174 185
     def _make_authors(self, n):
175 186
         Author.objects.all().delete()
176 187
         for i in range(n):
177 188
             Author.objects.create(name='Author %02i' % i, slug='a%s' % i)
178  
-

0 notes on commit d35b95c

Please sign in to comment.
Something went wrong with that request. Please try again.