Ticket #19240: 19240.diff

File 19240.diff, 2.0 KB (added by seawolf, 12 years ago)
  • django/views/generic/list.py

    diff --git a/django/views/generic/list.py b/django/views/generic/list.py
    index ec30c58..946dad6 100644
    a b class MultipleObjectMixin(ContextMixin):  
    5050        try:
    5151            page = paginator.page(page_number)
    5252            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,
    5657            })
    5758
    5859    def get_paginate_by(self, queryset):
  • tests/regressiontests/generic_views/list.py

    diff --git a/tests/regressiontests/generic_views/list.py b/tests/regressiontests/generic_views/list.py
    index 14dc1d7..6f07480 100644
    a b from __future__ import absolute_import  
    22
    33from django.core.exceptions import ImproperlyConfigured
    44from django.test import TestCase
     5from django.test.utils import override_settings
    56from django.views.generic.base import View
    67
    78from .models import Author, Artist
    class ListViewTests(TestCase):  
    171172        with self.assertNumQueries(3):
    172173            self.client.get('/list/authors/notempty/paginated/')
    173174
     175    @override_settings(DEBUG=True)
     176    def test_paginated_list_view_returns_useful_message_on_invalid_page(self):
     177        self._make_authors(1)
     178        res = self.client.get('/list/authors/paginated/2/')
     179        self.assertEqual(res.status_code, 404)
     180        self.assertEqual(res.context.get('reason'), "Invalid page (2): That page contains no results")
     181
    174182    def _make_authors(self, n):
    175183        Author.objects.all().delete()
    176184        for i in range(n):
    177185            Author.objects.create(name='Author %02i' % i, slug='a%s' % i)
    178 
Back to Top