summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-10-28 02:58:28 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-10-28 02:58:28 +0000
commitbaa1e90d4cf029b42e028ee23d999c99751a24e7 (patch)
tree3ddbab99b4c5541bc2aabb7036e5add469911ad7
parent8bc2f2a0b531c9e9bf7734b05ed3d3a7e86a526e (diff)
Fixed #14504 -- Corrected the way object_list is used in ListView to avoid overwriting context. Includes improved usage of unittest2 assertions. Thanks to Łukasz Rekucki for the final patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14372 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--AUTHORS1
-rw-r--r--django/views/generic/list.py2
-rw-r--r--tests/regressiontests/generic_views/list.py42
3 files changed, 25 insertions, 20 deletions
diff --git a/AUTHORS b/AUTHORS
index 2492c36a02..e1eaded9c3 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -399,6 +399,7 @@ answer newbie questions, and generally made Django that much better:
Philippe Raoult <philippe.raoult@n2nsoft.com>
Massimiliano Ravelli <massimiliano.ravelli@gmail.com>
Brian Ray <http://brianray.chipy.org/>
+ Łukasz Rekucki <lrekucki@gmail.com>
remco@diji.biz
Marc Remolt <m.remolt@webmasters.de>
Bruno Renié <buburno@gmail.com>
diff --git a/django/views/generic/list.py b/django/views/generic/list.py
index d01bacc956..ef90d75618 100644
--- a/django/views/generic/list.py
+++ b/django/views/generic/list.py
@@ -77,7 +77,7 @@ class MultipleObjectMixin(object):
"""
Get the context for this view.
"""
- queryset = kwargs.get('object_list')
+ queryset = kwargs.pop('object_list')
page_size = self.get_paginate_by(queryset)
if page_size:
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
diff --git a/tests/regressiontests/generic_views/list.py b/tests/regressiontests/generic_views/list.py
index 5d62aa8fb8..8f6af741f7 100644
--- a/tests/regressiontests/generic_views/list.py
+++ b/tests/regressiontests/generic_views/list.py
@@ -19,18 +19,19 @@ class ListViewTests(TestCase):
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
- self.assertEqual(res.context['paginator'], None)
- self.assertEqual(res.context['page_obj'], None)
- self.assertEqual(res.context['is_paginated'], False)
+ self.assertIs(res.context['authors'], res.context['object_list'])
+ self.assertIsNone(res.context['paginator'])
+ self.assertIsNone(res.context['page_obj'])
+ self.assertFalse(res.context['is_paginated'])
def test_paginated_queryset(self):
self._make_authors(100)
res = self.client.get('/list/authors/paginated/')
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
- self.assertEqual(len(res.context['authors']), 30)
- self.assertEqual(res.context['is_paginated'], True)
+ self.assertEqual(len(res.context['object_list']), 30)
+ self.assertIs(res.context['authors'], res.context['object_list'])
+ self.assertTrue(res.context['is_paginated'])
self.assertEqual(res.context['page_obj'].number, 1)
self.assertEqual(res.context['paginator'].num_pages, 4)
self.assertEqual(res.context['authors'][0].name, 'Author 00')
@@ -41,17 +42,18 @@ class ListViewTests(TestCase):
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
- self.assertEqual(res.context['paginator'], None)
- self.assertEqual(res.context['page_obj'], None)
- self.assertEqual(res.context['is_paginated'], False)
+ self.assertIs(res.context['authors'], res.context['object_list'])
+ self.assertIsNone(res.context['paginator'])
+ self.assertIsNone(res.context['page_obj'])
+ self.assertFalse(res.context['is_paginated'])
def test_paginated_get_page_by_query_string(self):
self._make_authors(100)
res = self.client.get('/list/authors/paginated/', {'page': '2'})
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
- self.assertEqual(len(res.context['authors']), 30)
+ self.assertEqual(len(res.context['object_list']), 30)
+ self.assertIs(res.context['authors'], res.context['object_list'])
self.assertEqual(res.context['authors'][0].name, 'Author 30')
self.assertEqual(res.context['page_obj'].number, 2)
@@ -59,7 +61,8 @@ class ListViewTests(TestCase):
self._make_authors(100)
res = self.client.get('/list/authors/paginated/', {'page': 'last'})
self.assertEqual(res.status_code, 200)
- self.assertEqual(len(res.context['authors']), 10)
+ self.assertEqual(len(res.context['object_list']), 10)
+ self.assertIs(res.context['authors'], res.context['object_list'])
self.assertEqual(res.context['authors'][0].name, 'Author 90')
self.assertEqual(res.context['page_obj'].number, 4)
@@ -68,7 +71,8 @@ class ListViewTests(TestCase):
res = self.client.get('/list/authors/paginated/3/')
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
- self.assertEqual(len(res.context['authors']), 30)
+ self.assertEqual(len(res.context['object_list']), 30)
+ self.assertIs(res.context['authors'], res.context['object_list'])
self.assertEqual(res.context['authors'][0].name, 'Author 60')
self.assertEqual(res.context['page_obj'].number, 3)
@@ -93,30 +97,30 @@ class ListViewTests(TestCase):
res = self.client.get('/list/authors/template_name/')
self.assertEqual(res.status_code, 200)
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
+ self.assertIs(res.context['authors'], res.context['object_list'])
self.assertTemplateUsed(res, 'generic_views/list.html')
def test_template_name_suffix(self):
res = self.client.get('/list/authors/template_name_suffix/')
self.assertEqual(res.status_code, 200)
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertEqual(list(res.context['authors']), list(Author.objects.all()))
+ self.assertIs(res.context['authors'], res.context['object_list'])
self.assertTemplateUsed(res, 'generic_views/author_objects.html')
def test_context_object_name(self):
res = self.client.get('/list/authors/context_object_name/')
self.assertEqual(res.status_code, 200)
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertEqual(list(res.context['author_list']), list(Author.objects.all()))
- self.assertFalse('authors' in res.context)
+ self.assertNotIn('authors', res.context)
+ self.assertIs(res.context['author_list'], res.context['object_list'])
self.assertTemplateUsed(res, 'generic_views/author_list.html')
def test_duplicate_context_object_name(self):
res = self.client.get('/list/authors/dupe_context_object_name/')
self.assertEqual(res.status_code, 200)
self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
- self.assertFalse('author_list' in res.context)
- self.assertFalse('authors' in res.context)
+ self.assertNotIn('authors', res.context)
+ self.assertNotIn('author_list', res.context)
self.assertTemplateUsed(res, 'generic_views/author_list.html')
def test_missing_items(self):