Fixed #28719 -- Added a helpful exception if MultipleObjectTemplateResponseMixin doesn't generate any template names.
This commit is contained in:
parent
a2851f204c
commit
ac6a4eb9f9
|
@ -181,7 +181,13 @@ class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
||||||
if hasattr(self.object_list, 'model'):
|
if hasattr(self.object_list, 'model'):
|
||||||
opts = self.object_list.model._meta
|
opts = self.object_list.model._meta
|
||||||
names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix))
|
names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix))
|
||||||
|
elif not names:
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"%(cls)s requires either a 'template_name' attribute "
|
||||||
|
"or a get_queryset() method that returns a QuerySet." % {
|
||||||
|
'cls': self.__class__.__name__,
|
||||||
|
}
|
||||||
|
)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,14 @@ class ListViewTests(TestCase):
|
||||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
self.client.get('/list/authors/invalid/')
|
self.client.get('/list/authors/invalid/')
|
||||||
|
|
||||||
|
def test_invalid_get_queryset(self):
|
||||||
|
msg = (
|
||||||
|
"AuthorListGetQuerysetReturnsNone requires either a 'template_name' "
|
||||||
|
"attribute or a get_queryset() method that returns a QuerySet."
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
|
self.client.get('/list/authors/get_queryset/')
|
||||||
|
|
||||||
def test_paginated_list_view_does_not_load_entire_table(self):
|
def test_paginated_list_view_does_not_load_entire_table(self):
|
||||||
# Regression test for #17535
|
# Regression test for #17535
|
||||||
self._make_authors(3)
|
self._make_authors(3)
|
||||||
|
|
|
@ -132,6 +132,10 @@ urlpatterns = [
|
||||||
path('list/authors/context_object_name/', views.AuthorList.as_view(context_object_name='author_list')),
|
path('list/authors/context_object_name/', views.AuthorList.as_view(context_object_name='author_list')),
|
||||||
path('list/authors/dupe_context_object_name/', views.AuthorList.as_view(context_object_name='object_list')),
|
path('list/authors/dupe_context_object_name/', views.AuthorList.as_view(context_object_name='object_list')),
|
||||||
path('list/authors/invalid/', views.AuthorList.as_view(queryset=None)),
|
path('list/authors/invalid/', views.AuthorList.as_view(queryset=None)),
|
||||||
|
path(
|
||||||
|
'list/authors/get_queryset/',
|
||||||
|
views.AuthorListGetQuerysetReturnsNone.as_view(),
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
'list/authors/paginated/custom_class/',
|
'list/authors/paginated/custom_class/',
|
||||||
views.AuthorList.as_view(paginate_by=5, paginator_class=views.CustomPaginator),
|
views.AuthorList.as_view(paginate_by=5, paginator_class=views.CustomPaginator),
|
||||||
|
|
|
@ -66,6 +66,11 @@ class AuthorList(generic.ListView):
|
||||||
queryset = Author.objects.all()
|
queryset = Author.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class AuthorListGetQuerysetReturnsNone(AuthorList):
|
||||||
|
def get_queryset(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class BookList(generic.ListView):
|
class BookList(generic.ListView):
|
||||||
model = Book
|
model = Book
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue