Ticket #14504: ticket14504.diff

File ticket14504.diff, 6.7 KB (added by lrekucki, 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 d01bacc..ef90d75 100644
    a b class MultipleObjectMixin(object): 
    7777        """
    7878        Get the context for this view.
    7979        """
    80         queryset = kwargs.get('object_list')
     80        queryset = kwargs.pop('object_list')
    8181        page_size = self.get_paginate_by(queryset)
    8282        if page_size:
    8383            paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
  • tests/regressiontests/generic_views/list.py

    diff --git a/tests/regressiontests/generic_views/list.py b/tests/regressiontests/generic_views/list.py
    index 5d62aa8..8f6af74 100644
    a b class ListViewTests(TestCase): 
    1919        self.assertEqual(res.status_code, 200)
    2020        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    2121        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    22         self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
    23         self.assertEqual(res.context['paginator'], None)
    24         self.assertEqual(res.context['page_obj'], None)
    25         self.assertEqual(res.context['is_paginated'], False)
     22        self.assertIs(res.context['authors'], res.context['object_list'])
     23        self.assertIsNone(res.context['paginator'])
     24        self.assertIsNone(res.context['page_obj'])
     25        self.assertFalse(res.context['is_paginated'])
    2626
    2727    def test_paginated_queryset(self):
    2828        self._make_authors(100)
    2929        res = self.client.get('/list/authors/paginated/')
    3030        self.assertEqual(res.status_code, 200)
    3131        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    32         self.assertEqual(len(res.context['authors']), 30)
    33         self.assertEqual(res.context['is_paginated'], True)
     32        self.assertEqual(len(res.context['object_list']), 30)
     33        self.assertIs(res.context['authors'], res.context['object_list'])
     34        self.assertTrue(res.context['is_paginated'])
    3435        self.assertEqual(res.context['page_obj'].number, 1)
    3536        self.assertEqual(res.context['paginator'].num_pages, 4)
    3637        self.assertEqual(res.context['authors'][0].name, 'Author 00')
    class ListViewTests(TestCase): 
    4142        self.assertEqual(res.status_code, 200)
    4243        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    4344        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    44         self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
    45         self.assertEqual(res.context['paginator'], None)
    46         self.assertEqual(res.context['page_obj'], None)
    47         self.assertEqual(res.context['is_paginated'], False)
     45        self.assertIs(res.context['authors'], res.context['object_list'])
     46        self.assertIsNone(res.context['paginator'])
     47        self.assertIsNone(res.context['page_obj'])
     48        self.assertFalse(res.context['is_paginated'])
    4849
    4950    def test_paginated_get_page_by_query_string(self):
    5051        self._make_authors(100)
    5152        res = self.client.get('/list/authors/paginated/', {'page': '2'})
    5253        self.assertEqual(res.status_code, 200)
    5354        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    54         self.assertEqual(len(res.context['authors']), 30)
     55        self.assertEqual(len(res.context['object_list']), 30)
     56        self.assertIs(res.context['authors'], res.context['object_list'])
    5557        self.assertEqual(res.context['authors'][0].name, 'Author 30')
    5658        self.assertEqual(res.context['page_obj'].number, 2)
    5759
    class ListViewTests(TestCase): 
    5961        self._make_authors(100)
    6062        res = self.client.get('/list/authors/paginated/', {'page': 'last'})
    6163        self.assertEqual(res.status_code, 200)
    62         self.assertEqual(len(res.context['authors']), 10)
     64        self.assertEqual(len(res.context['object_list']), 10)
     65        self.assertIs(res.context['authors'], res.context['object_list'])
    6366        self.assertEqual(res.context['authors'][0].name, 'Author 90')
    6467        self.assertEqual(res.context['page_obj'].number, 4)
    6568
    class ListViewTests(TestCase): 
    6871        res = self.client.get('/list/authors/paginated/3/')
    6972        self.assertEqual(res.status_code, 200)
    7073        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    71         self.assertEqual(len(res.context['authors']), 30)
     74        self.assertEqual(len(res.context['object_list']), 30)
     75        self.assertIs(res.context['authors'], res.context['object_list'])
    7276        self.assertEqual(res.context['authors'][0].name, 'Author 60')
    7377        self.assertEqual(res.context['page_obj'].number, 3)
    7478
    class ListViewTests(TestCase): 
    9397        res = self.client.get('/list/authors/template_name/')
    9498        self.assertEqual(res.status_code, 200)
    9599        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    96         self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
     100        self.assertIs(res.context['authors'], res.context['object_list'])
    97101        self.assertTemplateUsed(res, 'generic_views/list.html')
    98102
    99103    def test_template_name_suffix(self):
    100104        res = self.client.get('/list/authors/template_name_suffix/')
    101105        self.assertEqual(res.status_code, 200)
    102106        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    103         self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
     107        self.assertIs(res.context['authors'], res.context['object_list'])
    104108        self.assertTemplateUsed(res, 'generic_views/author_objects.html')
    105109
    106110    def test_context_object_name(self):
    107111        res = self.client.get('/list/authors/context_object_name/')
    108112        self.assertEqual(res.status_code, 200)
    109113        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    110         self.assertEqual(list(res.context['author_list']), list(Author.objects.all()))
    111         self.assertFalse('authors' in res.context)
     114        self.assertNotIn('authors', res.context)
     115        self.assertIs(res.context['author_list'], res.context['object_list'])
    112116        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    113117
    114118    def test_duplicate_context_object_name(self):
    115119        res = self.client.get('/list/authors/dupe_context_object_name/')
    116120        self.assertEqual(res.status_code, 200)
    117121        self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
    118         self.assertFalse('author_list' in res.context)
    119         self.assertFalse('authors' in res.context)
     122        self.assertNotIn('authors', res.context)
     123        self.assertNotIn('author_list', res.context)
    120124        self.assertTemplateUsed(res, 'generic_views/author_list.html')
    121125
    122126    def test_missing_items(self):
Back to Top