diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py
index 1e39c4d..fd1bd7a 100644
a
|
b
|
def object_detail(request, queryset, object_id=None, slug=None,
|
124 | 124 | try: |
125 | 125 | obj = queryset.get() |
126 | 126 | except ObjectDoesNotExist: |
127 | | raise Http404("No %s found matching the query" % (model._meta.verbose_name)) |
| 127 | raise Http404(u"No %s found matching the query" % (model._meta.verbose_name)) |
128 | 128 | if not template_name: |
129 | 129 | template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower()) |
130 | 130 | if template_name_field: |
diff --git a/tests/regressiontests/views/tests/generic/object_list.py b/tests/regressiontests/views/tests/generic/object_list.py
index 4f902ee..2f5d842 100644
a
|
b
|
|
| 1 | from django.http import Http404 |
1 | 2 | from django.test import TestCase |
| 3 | from django.views.generic import list_detail |
| 4 | |
| 5 | from regressiontests.views.models import Article |
2 | 6 | |
3 | 7 | |
4 | 8 | class ObjectListTest(TestCase): |
… |
… |
class ObjectListTest(TestCase):
|
34 | 38 | url = '/views/object_list_no_paginate_by/page1/' |
35 | 39 | response = self.check_pagination(url, 200) |
36 | 40 | self.assertEqual(response.context['is_paginated'], False) |
| 41 | |
| 42 | |
| 43 | class ObjectDetailTest(TestCase): |
| 44 | fixtures = ['testdata.json'] |
| 45 | |
| 46 | def test_object_detail_404(self): |
| 47 | a = Article.objects.all()[0] |
| 48 | |
| 49 | self.assertContains(self.client.get('/views/object_detail/%d/' % a.pk), |
| 50 | 'Article detail template.') |
| 51 | |
| 52 | response = self.client.get('/views/object_detail/42/') |
| 53 | self.assertEqual(response.status_code, 404) |
| 54 | |
| 55 | def test_object_detail_404_raises(self): |
| 56 | try: |
| 57 | list_detail.object_detail({}, |
| 58 | queryset=Article.objects.all(), |
| 59 | object_id=42) |
| 60 | except Http404, e: |
| 61 | # All is well |
| 62 | pass |
| 63 | except: |
| 64 | # Re-raise if another exception happens |
| 65 | raise |
| 66 | |
| 67 | # Regression test for #12418: ObjectDoesNotExist message should be unicode |
| 68 | # so that string interpolation with ugettext_lazy objects works correctly. |
| 69 | self.assertEqual(e.args[0], u'No article found matching the query') |
| 70 | self.assertEqual(type(e.args[0]), unicode) |
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py
index d1412cd..da6ff9c 100644
a
|
b
|
urlpatterns += patterns('django.views.generic.list_detail',
|
118 | 118 | (r'^object_list/page(?P<page>[\w]*)/$', 'object_list', object_list_dict), |
119 | 119 | (r'^object_list_no_paginate_by/page(?P<page>[0-9]+)/$', 'object_list', |
120 | 120 | object_list_no_paginate_by), |
| 121 | (r'^object_detail/(?P<object_id>\d+)/$', 'object_detail', |
| 122 | object_list_no_paginate_by), |
121 | 123 | ) |
122 | 124 | |
123 | 125 | # a view that raises an exception for the debug view |