Ticket #10927: shortcut.diff
File shortcut.diff, 2.8 KB (added by , 16 years ago) |
---|
-
django/contrib/contenttypes/views.py
diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py index 4285be3..2696120 100644
a b def shortcut(request, content_type_id, object_id): 9 9 try: 10 10 content_type = ContentType.objects.get(pk=content_type_id) 11 11 obj = content_type.get_object_for_this_type(pk=object_id) 12 except ObjectDoesNotExist:12 except (ObjectDoesNotExist, ValueError): 13 13 raise http.Http404("Content type %s object %s doesn't exist" % (content_type_id, object_id)) 14 14 try: 15 15 absurl = obj.get_absolute_url() -
tests/regressiontests/views/tests/defaults.py
diff --git a/tests/regressiontests/views/tests/defaults.py b/tests/regressiontests/views/tests/defaults.py index bf490d7..bef80e4 100644
a b class DefaultsTests(TestCase): 10 10 """Test django views in django/views/defaults.py""" 11 11 fixtures = ['testdata.json'] 12 12 13 def test_shor cut_with_absolute_url(self):13 def test_shortcut_with_absolute_url(self): 14 14 "Can view a shortcut an Author object that has with a get_absolute_url method" 15 15 for obj in Author.objects.all(): 16 16 short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk) … … class DefaultsTests(TestCase): 25 25 response = self.client.get(short_url) 26 26 self.assertEquals(response.status_code, 404) 27 27 28 def test_wrong_type_pk(self): 29 an_article = Article.objects.all()[0] 30 short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, 'nobody/expects') 31 response = self.client.get(short_url) 32 self.assertEquals(response.status_code, 404) 33 34 def test_shortcut_bad_pk(self): 35 "Shortcuts for an object that has with a get_absolute_url method raises 404" 36 short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, '4242424242') 37 response = self.client.get(short_url) 38 self.assertEquals(response.status_code, 404) 39 40 def test_nonint_content_type(self): 41 an_article = Article.objects.all()[0] 42 short_url = '/views/shortcut/%s/%s/' % ('spam', an_article.pk) 43 response = self.client.get(short_url) 44 self.assertEquals(response.status_code, 404) 45 46 def test_bad_content_type(self): 47 an_article = Article.objects.all()[0] 48 short_url = '/views/shortcut/%s/%s/' % (4242424242, an_article.pk) 49 response = self.client.get(short_url) 50 self.assertEquals(response.status_code, 404) 51 28 52 def test_page_not_found(self): 29 53 "A 404 status is returned by the page_not_found view" 30 54 non_existing_urls = ['/views/non_existing_url/', # this is in urls.py