Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20121 -- Removed LogEntry.get_admin_url's hard-coded path.

Updated LogEntry.get_admin_url to use 'reverse' instead
of a hard-coded path.
  • Loading branch information...
commit a4b8a4b632dbb6d9fed1a8654aed99a9c53560d4 1 parent ccf8d81
Adam Wentz authored March 23, 2013 charettes committed March 25, 2013
4  django/contrib/admin/models.py
@@ -4,6 +4,7 @@
4 4
 from django.conf import settings
5 5
 from django.contrib.contenttypes.models import ContentType
6 6
 from django.contrib.admin.util import quote
  7
+from django.core.urlresolvers import reverse
7 8
 from django.utils.translation import ugettext, ugettext_lazy as _
8 9
 from django.utils.encoding import smart_text
9 10
 from django.utils.encoding import python_2_unicode_compatible
@@ -72,5 +73,6 @@ def get_admin_url(self):
72 73
         This is relative to the Django admin index page.
73 74
         """
74 75
         if self.content_type and self.object_id:
75  
-            return "%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id))
  76
+            url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
  77
+            return reverse(url_name, args=(quote(self.object_id),))
76 78
         return None
7  tests/admin_views/tests.py
@@ -25,6 +25,7 @@
25 25
 from django.contrib.auth import REDIRECT_FIELD_NAME
26 26
 from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
27 27
 from django.contrib.contenttypes.models import ContentType
  28
+from django.core.urlresolvers import reverse
28 29
 from django.forms.util import ErrorList
29 30
 from django.template.response import TemplateResponse
30 31
 from django.test import TestCase
@@ -1484,13 +1485,15 @@ def test_changelist_to_changeform_link(self):
1484 1485
     def test_recentactions_link(self):
1485 1486
         "The link from the recent actions list referring to the changeform of the object should be quoted"
1486 1487
         response = self.client.get('/test_admin/admin/')
1487  
-        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
  1488
+        link = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(self.pk),))
  1489
+        should_contain = """<a href="%s">%s</a>""" % (link, escape(self.pk))
1488 1490
         self.assertContains(response, should_contain)
1489 1491
 
1490 1492
     def test_recentactions_without_content_type(self):
1491 1493
         "If a LogEntry is missing content_type it will not display it in span tag under the hyperlink."
1492 1494
         response = self.client.get('/test_admin/admin/')
1493  
-        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
  1495
+        link = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(self.pk),))
  1496
+        should_contain = """<a href="%s">%s</a>""" % (link, escape(self.pk))
1494 1497
         self.assertContains(response, should_contain)
1495 1498
         should_contain = "Model with string primary key"  # capitalized in Recent Actions
1496 1499
         self.assertContains(response, should_contain)

0 notes on commit a4b8a4b

Please sign in to comment.
Something went wrong with that request. Please try again.