Code

Ticket #12418: fix12418.patch

File fix12418.patch, 3.0 KB (added by mk, 4 years ago)
  • django/views/generic/list_detail.py

    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, 
    124124    try: 
    125125        obj = queryset.get() 
    126126    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)) 
    128128    if not template_name: 
    129129        template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower()) 
    130130    if template_name_field: 
  • tests/regressiontests/views/tests/generic/object_list.py

    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  
     1from django.http import Http404 
    12from django.test import TestCase 
     3from django.views.generic import list_detail 
     4 
     5from regressiontests.views.models import Article 
    26 
    37 
    48class ObjectListTest(TestCase): 
    class ObjectListTest(TestCase): 
    3438        url = '/views/object_list_no_paginate_by/page1/' 
    3539        response = self.check_pagination(url, 200) 
    3640        self.assertEqual(response.context['is_paginated'], False) 
     41 
     42 
     43class 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) 
  • tests/regressiontests/views/urls.py

    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', 
    118118    (r'^object_list/page(?P<page>[\w]*)/$', 'object_list', object_list_dict), 
    119119    (r'^object_list_no_paginate_by/page(?P<page>[0-9]+)/$', 'object_list', 
    120120     object_list_no_paginate_by), 
     121    (r'^object_detail/(?P<object_id>\d+)/$', 'object_detail', 
     122     object_list_no_paginate_by), 
    121123) 
    122124 
    123125# a view that raises an exception for the debug view