Loading django/views/generic/detail.py +28 −22 Original line number Diff line number Diff line Loading @@ -159,6 +159,12 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin): self.model._meta.model_name, self.template_name_suffix )) # If we still haven't managed to find any template names, we should # re-raise the ImproperlyConfigured to alert the user. if not names: raise return names Loading tests/generic_views/test_base.py +12 −0 Original line number Diff line number Diff line Loading @@ -468,3 +468,15 @@ class UseMultipleObjectMixinTest(unittest.TestCase): # Overwrite the view's queryset with queryset from kwarg context = test_view.get_context_data(object_list=queryset) self.assertEqual(context['object_list'], queryset) class SingleObjectTemplateResponseMixinTest(unittest.TestCase): def test_template_mixin_without_template(self): """ We want to makes sure that if you use a template mixin, but forget the template, it still tells you it's ImproperlyConfigured instead of TemplateDoesNotExist. """ view = views.TemplateResponseWithoutTemplate() self.assertRaises(ImproperlyConfigured, view.get_template_names) tests/generic_views/views.py +8 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,14 @@ class NaiveAuthorCreate(generic.CreateView): fields = '__all__' class TemplateResponseWithoutTemplate(generic.detail.SingleObjectTemplateResponseMixin, generic.View): # we don't define the usual template_name here def __init__(self): # Dummy object, but attr is required by get_template_name() self.object = None class AuthorCreate(generic.CreateView): model = Author success_url = '/list/authors/' Loading Loading
django/views/generic/detail.py +28 −22 Original line number Diff line number Diff line Loading @@ -159,6 +159,12 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin): self.model._meta.model_name, self.template_name_suffix )) # If we still haven't managed to find any template names, we should # re-raise the ImproperlyConfigured to alert the user. if not names: raise return names Loading
tests/generic_views/test_base.py +12 −0 Original line number Diff line number Diff line Loading @@ -468,3 +468,15 @@ class UseMultipleObjectMixinTest(unittest.TestCase): # Overwrite the view's queryset with queryset from kwarg context = test_view.get_context_data(object_list=queryset) self.assertEqual(context['object_list'], queryset) class SingleObjectTemplateResponseMixinTest(unittest.TestCase): def test_template_mixin_without_template(self): """ We want to makes sure that if you use a template mixin, but forget the template, it still tells you it's ImproperlyConfigured instead of TemplateDoesNotExist. """ view = views.TemplateResponseWithoutTemplate() self.assertRaises(ImproperlyConfigured, view.get_template_names)
tests/generic_views/views.py +8 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,14 @@ class NaiveAuthorCreate(generic.CreateView): fields = '__all__' class TemplateResponseWithoutTemplate(generic.detail.SingleObjectTemplateResponseMixin, generic.View): # we don't define the usual template_name here def __init__(self): # Dummy object, but attr is required by get_template_name() self.object = None class AuthorCreate(generic.CreateView): model = Author success_url = '/list/authors/' Loading