diff -r d656e3f8e358 django/contrib/admin/sites.py
a
|
b
|
|
474 | 474 | # URLs starting with 'r/' are for the "View on site" links. |
475 | 475 | elif url.startswith('r/'): |
476 | 476 | from django.contrib.contenttypes.views import shortcut |
477 | | return shortcut(request, *url.split('/')[1:]) |
| 477 | return shortcut(request, *url.split('/', 2)[1:]) |
478 | 478 | else: |
479 | 479 | if '/' in url: |
480 | 480 | return self.model_page(request, *url.split('/', 2)) |
diff -r d656e3f8e358 tests/regressiontests/admin_views/models.py
a
|
b
|
|
122 | 122 | |
123 | 123 | def __unicode__(self): |
124 | 124 | return self.id |
| 125 | |
| 126 | def get_absolute_url(self): |
| 127 | return "/" + self.id |
125 | 128 | |
126 | 129 | class Color(models.Model): |
127 | 130 | value = models.CharField(max_length=10) |
diff -r d656e3f8e358 tests/regressiontests/admin_views/tests.py
a
|
b
|
|
22 | 22 | set |
23 | 23 | except NameError: |
24 | 24 | from sets import Set as set |
| 25 | |
| 26 | class LegacyAdminViewBasicTest(TestCase): |
| 27 | """This test can be removed when we deprecate the root() AdminSite method in Django release 1.1 + 2.""" |
| 28 | |
| 29 | fixtures = ['admin-views-users.xml'] |
| 30 | urlbit = 'legacy_admin' |
| 31 | |
| 32 | def setUp(self): |
| 33 | self.client.login(username='super', password='secret') |
| 34 | |
| 35 | def tearDown(self): |
| 36 | self.client.logout() |
| 37 | |
| 38 | def testShortcutWithSlash(self): |
| 39 | """Ensures the 'view on Site' links work for models with string PKs values that contain slashes.""" |
| 40 | obj = ModelWithStringPrimaryKey(id="pk/with/slashes") |
| 41 | obj.save() |
| 42 | content_type_pk = ContentType.objects.get_for_model(ModelWithStringPrimaryKey).pk |
| 43 | short_url = '/test_admin/%s/r/%s/%s/' % (self.urlbit, content_type_pk, obj.pk) |
| 44 | response = self.client.get(short_url) |
| 45 | self.assertRedirects(response, 'http://example.com%s' % obj.get_absolute_url(), |
| 46 | status_code=302, target_status_code=404) |
| 47 | |
25 | 48 | |
26 | 49 | class AdminViewBasicTest(TestCase): |
27 | 50 | fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml'] |
diff -r d656e3f8e358 tests/regressiontests/admin_views/urls.py
a
|
b
|
|
2 | 2 | from django.contrib import admin |
3 | 3 | import views |
4 | 4 | import customadmin |
| 5 | import legacyadmin |
5 | 6 | |
6 | 7 | urlpatterns = patterns('', |
7 | 8 | (r'^admin/doc/', include('django.contrib.admindocs.urls')), |
8 | 9 | (r'^admin/secure-view/$', views.secure_view), |
9 | 10 | (r'^admin/', include(admin.site.urls)), |
10 | 11 | (r'^admin2/', include(customadmin.site.urls)), |
| 12 | (r'^legacy_admin/(.*)', legacyadmin.site.root), |
11 | 13 | ) |