Code

Ticket #17200: 17200-patch-and-test.diff

File 17200-patch-and-test.diff, 2.6 KB (added by dchandek, 3 years ago)

Initial attempt at patch + unit test. Note that i18n not applied to "View on site" in test.

Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 17095)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -1088,7 +1088,7 @@
6         context = {
7             'title': _('Change %s') % force_unicode(opts.verbose_name),
8             'adminform': adminForm,
9-            'object_id': object_id,
10+            'object_id': unquote(object_id),
11             'original': obj,
12             'is_popup': "_popup" in request.REQUEST,
13             'media': mark_safe(media),
14Index: tests/regressiontests/admin_views/tests.py
15===================================================================
16--- tests/regressiontests/admin_views/tests.py  (revision 17095)
17+++ tests/regressiontests/admin_views/tests.py  (working copy)
18@@ -14,7 +14,7 @@
19 from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
20 from django.contrib.admin.models import LogEntry, DELETION
21 from django.contrib.admin.sites import LOGIN_FORM_KEY
22-from django.contrib.admin.util import quote
23+from django.contrib.admin.util import quote, unquote
24 from django.contrib.admin.views.main import IS_POPUP_VAR
25 from django.contrib.auth import REDIRECT_FIELD_NAME, admin
26 from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
27@@ -1206,6 +1206,9 @@
28         response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(self.pk))
29         self.assertContains(response, escape(self.pk))
30         self.assertEqual(response.status_code, 200)
31+        content_type_pk = ContentType.objects.get_for_model(ModelWithStringPrimaryKey).pk
32+        should_contain = """<a href="../../../r/%s/%s/" class="viewsitelink">View on site</a>""" % (content_type_pk, escape(self.pk))
33+        self.assertContains(response, should_contain)
34 
35     def test_changelist_to_changeform_link(self):
36         "The link from the changelist referring to the changeform of the object should be quoted"
37Index: tests/regressiontests/admin_views/models.py
38===================================================================
39--- tests/regressiontests/admin_views/models.py (revision 17095)
40+++ tests/regressiontests/admin_views/models.py (working copy)
41@@ -99,7 +99,12 @@
42     def __unicode__(self):
43         return self.id
44 
45+    def get_absolute_url(self):
46+        # Need this to cause "view on site" link to appear on admin change form.
47+        # We're not testing the specific URL produced by this method.
48+        return '/%s/' % self.id
49 
50+
51 class Color(models.Model):
52     value = models.CharField(max_length=10)
53     warm = models.BooleanField()