Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecated django.views.defaults.shortcut.
- Loading branch information
Showing
12 changed files
with
156 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,10 @@ | |||
import warnings | |||
|
|||
from django.conf.urls import patterns | from django.conf.urls import patterns | ||
|
|
||
warnings.warn("django.conf.urls.shortcut will be removed in Django 1.8.", | |||
PendingDeprecationWarning) | |||
|
|||
urlpatterns = patterns('django.views', | urlpatterns = patterns('django.views', | ||
(r'^(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'defaults.shortcut'), | (r'^(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'defaults.shortcut'), | ||
) | ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,47 @@ | |||
[ | |||
{ | |||
"pk": 1, | |||
"model": "contenttypes_tests.author", | |||
"fields": { | |||
"name": "Boris" | |||
} | |||
}, | |||
{ | |||
"pk": 1, | |||
"model": "contenttypes_tests.article", | |||
"fields": { | |||
"author": 1, | |||
"title": "Old Article", | |||
"slug": "old_article", | |||
"date_created": "2001-01-01 21:22:23" | |||
} | |||
}, | |||
{ | |||
"pk": 2, | |||
"model": "contenttypes_tests.article", | |||
"fields": { | |||
"author": 1, | |||
"title": "Current Article", | |||
"slug": "current_article", | |||
"date_created": "2007-09-17 21:22:23" | |||
} | |||
}, | |||
{ | |||
"pk": 3, | |||
"model": "contenttypes_tests.article", | |||
"fields": { | |||
"author": 1, | |||
"title": "Future Article", | |||
"slug": "future_article", | |||
"date_created": "3000-01-01 21:22:23" | |||
} | |||
}, | |||
{ | |||
"pk": 1, | |||
"model": "sites.site", | |||
"fields": { | |||
"domain": "testserver", | |||
"name": "testserver" | |||
} | |||
} | |||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
from __future__ import absolute_import, unicode_literals | |||
|
|||
from django.db import models | |||
from django.utils.encoding import python_2_unicode_compatible | |||
|
|||
@python_2_unicode_compatible | |||
class Author(models.Model): | |||
name = models.CharField(max_length=100) | |||
|
|||
def __str__(self): | |||
return self.name | |||
|
|||
def get_absolute_url(self): | |||
return '/views/authors/%s/' % self.id | |||
|
|||
@python_2_unicode_compatible | |||
class Article(models.Model): | |||
title = models.CharField(max_length=100) | |||
slug = models.SlugField() | |||
author = models.ForeignKey(Author) | |||
date_created = models.DateTimeField() | |||
|
|||
def __str__(self): | |||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,47 @@ | |||
from __future__ import absolute_import, unicode_literals | |||
|
|||
from django.contrib.contenttypes.models import ContentType | |||
from django.test import TestCase | |||
|
|||
from .models import Author, Article | |||
|
|||
class ContentTypesViewsTests(TestCase): | |||
fixtures = ['testdata.json'] | |||
urls = 'contenttypes_tests.urls' | |||
|
|||
def test_shortcut_with_absolute_url(self): | |||
"Can view a shortcut for an Author object that has a get_absolute_url method" | |||
for obj in Author.objects.all(): | |||
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk) | |||
response = self.client.get(short_url) | |||
self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(), | |||
status_code=302, target_status_code=404) | |||
|
|||
def test_shortcut_no_absolute_url(self): | |||
"Shortcuts for an object that has no get_absolute_url method raises 404" | |||
for obj in Article.objects.all(): | |||
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk) | |||
response = self.client.get(short_url) | |||
self.assertEqual(response.status_code, 404) | |||
|
|||
def test_wrong_type_pk(self): | |||
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, 'nobody/expects') | |||
response = self.client.get(short_url) | |||
self.assertEqual(response.status_code, 404) | |||
|
|||
def test_shortcut_bad_pk(self): | |||
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, '42424242') | |||
response = self.client.get(short_url) | |||
self.assertEqual(response.status_code, 404) | |||
|
|||
def test_nonint_content_type(self): | |||
an_author = Author.objects.all()[0] | |||
short_url = '/shortcut/%s/%s/' % ('spam', an_author.pk) | |||
response = self.client.get(short_url) | |||
self.assertEqual(response.status_code, 404) | |||
|
|||
def test_bad_content_type(self): | |||
an_author = Author.objects.all()[0] | |||
short_url = '/shortcut/%s/%s/' % (42424242, an_author.pk) | |||
response = self.client.get(short_url) | |||
self.assertEqual(response.status_code, 404) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
from __future__ import absolute_import, unicode_literals | |||
|
|||
from django.conf.urls import patterns | |||
|
|||
urlpatterns = patterns('', | |||
(r'^shortcut/(\d+)/(.*)/$', 'django.contrib.contenttypes.views.shortcut'), | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters