Ticket #15698: patch.diff

File patch.diff, 6.9 KB (added by etianen, 4 years ago)

Patch with tests

  • django/views/generic/list.py

    diff --git a/django/views/generic/list.py b/django/views/generic/list.py
    index 5668457..5135763 100644
    a b class MultipleObjectMixin(object): 
    8989        """
    9090        queryset = kwargs.pop('object_list')
    9191        page_size = self.get_paginate_by(queryset)
     92        context_object_name = self.get_context_object_name(queryset)
    9293        if page_size:
    9394            paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
    9495            context = {
    class MultipleObjectMixin(object): 
    105106                'object_list': queryset
    106107            }
    107108        context.update(kwargs)
    108         context_object_name = self.get_context_object_name(queryset)
    109109        if context_object_name is not None:
    110110            context[context_object_name] = queryset
    111111        return context
  • tests/regressiontests/generic_views/dates.py

    diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py
    index d5345be..14eba72 100644
    a b class YearArchiveViewTests(TestCase): 
    118118        res = self.client.get('/dates/books/%s/allow_future/' % year)
    119119        self.assertEqual(res.status_code, 200)
    120120        self.assertEqual(list(res.context['date_list']), [datetime.datetime(year, 1, 1)])
    121 
     121   
     122    def test_year_view_paginated(self):
     123        res = self.client.get('/dates/books/2006/paginated/')
     124        self.assertEqual(res.status_code, 200)
     125        self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2006)))
     126        self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2006)))
     127        self.assertTemplateUsed(res, 'generic_views/book_archive_year.html')
     128   
    122129    def test_year_view_invalid_pattern(self):
    123130        res = self.client.get('/dates/books/no_year/')
    124131        self.assertEqual(res.status_code, 404)
    class MonthArchiveViewTests(TestCase): 
    189196        self.assertEqual(res.status_code, 200)
    190197        self.assertEqual(res.context['next_month'], future)
    191198        self.assertEqual(res.context['previous_month'], datetime.date(2006, 5, 1))
    192 
     199       
     200    def test_month_view_paginated(self):
     201        res = self.client.get('/dates/books/2008/oct/paginated/')
     202        self.assertEqual(res.status_code, 200)
     203        self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10)))
     204        self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10)))
     205        self.assertTemplateUsed(res, 'generic_views/book_archive_month.html')
     206       
    193207    def test_custom_month_format(self):
    194208        res = self.client.get('/dates/books/2008/10/')
    195209        self.assertEqual(res.status_code, 200)
    class WeekArchiveViewTests(TestCase): 
    250264        res = self.client.get('/dates/books/%s/week/1/allow_future/' % future.year)
    251265        self.assertEqual(res.status_code, 200)
    252266        self.assertEqual(list(res.context['book_list']), [b])
    253 
     267       
     268    def test_week_view_paginated(self):
     269        week_start = datetime.date(2008, 9, 28)
     270        week_end = week_start + datetime.timedelta(days=7)
     271        res = self.client.get('/dates/books/2008/week/39/')
     272        self.assertEqual(res.status_code, 200)
     273        self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__gte=week_start, pubdate__lt=week_end)))
     274        self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__gte=week_start, pubdate__lt=week_end)))
     275        self.assertTemplateUsed(res, 'generic_views/book_archive_week.html')
     276       
    254277    def test_week_view_invalid_pattern(self):
    255278        res = self.client.get('/dates/books/2007/week/no_week/')
    256279        self.assertEqual(res.status_code, 404)
    class DayArchiveViewTests(TestCase): 
    326349        self.assertEqual(res.status_code, 200)
    327350        self.assertEqual(res.context['next_day'], future)
    328351        self.assertEqual(res.context['previous_day'], datetime.date(2006, 5, 1))
    329 
     352   
     353    def test_day_view_paginated(self):
     354        res = self.client.get('/dates/books/2008/oct/1/')
     355        self.assertEqual(res.status_code, 200)
     356        self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10, pubdate__day=1)))
     357        self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10, pubdate__day=1)))
     358        self.assertTemplateUsed(res, 'generic_views/book_archive_day.html')
     359   
    330360    def test_next_prev_context(self):
    331361        res = self.client.get('/dates/books/2008/oct/01/')
    332362        self.assertEqual(res.content, "Archive for Oct. 1, 2008. Previous day is May 1, 2006")
  • tests/regressiontests/generic_views/urls.py

    diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
    index c06b5d8..067c1f6 100644
    a b urlpatterns = patterns('', 
    146146        views.BookYearArchive.as_view(allow_empty=True)),
    147147    (r'^dates/books/(?P<year>\d{4})/allow_future/$',
    148148        views.BookYearArchive.as_view(allow_future=True)),
     149    (r'^dates/books/(?P<year>\d{4})/paginated/$',
     150        views.BookYearArchive.as_view(make_object_list=True, paginate_by=30)),
    149151    (r'^dates/books/no_year/$',
    150152        views.BookYearArchive.as_view()),
    151153
    urlpatterns = patterns('', 
    158160        views.BookMonthArchive.as_view(allow_empty=True)),
    159161    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/allow_future/$',
    160162        views.BookMonthArchive.as_view(allow_future=True)),
     163    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/paginated/$',
     164        views.BookMonthArchive.as_view(paginate_by=30)),
    161165    (r'^dates/books/(?P<year>\d{4})/no_month/$',
    162166        views.BookMonthArchive.as_view()),
    163167
    urlpatterns = patterns('', 
    168172        views.BookWeekArchive.as_view(allow_empty=True)),
    169173    (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/allow_future/$',
    170174        views.BookWeekArchive.as_view(allow_future=True)),
     175    (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/paginated/$',
     176        views.BookWeekArchive.as_view(paginate_by=30)),
    171177    (r'^dates/books/(?P<year>\d{4})/week/no_week/$',
    172178        views.BookWeekArchive.as_view()),
    173179    (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/monday/$',
    urlpatterns = patterns('', 
    182188        views.BookDayArchive.as_view(allow_empty=True)),
    183189    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/allow_future/$',
    184190        views.BookDayArchive.as_view(allow_future=True)),
     191    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/paginated/$',
     192        views.BookDayArchive.as_view(paginate_by=True)),
    185193    (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/no_day/$',
    186194        views.BookDayArchive.as_view()),
    187195
Back to Top