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.
This commit is contained in:
parent
ccf8d81113
commit
a4b8a4b632
|
@ -4,6 +4,7 @@ from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.admin.util import quote
|
from django.contrib.admin.util import quote
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
@ -72,5 +73,6 @@ class LogEntry(models.Model):
|
||||||
This is relative to the Django admin index page.
|
This is relative to the Django admin index page.
|
||||||
"""
|
"""
|
||||||
if self.content_type and self.object_id:
|
if self.content_type and self.object_id:
|
||||||
return "%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id))
|
url_name = 'admin:%s_%s_change' % (self.content_type.app_label, self.content_type.model)
|
||||||
|
return reverse(url_name, args=(quote(self.object_id),))
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -25,6 +25,7 @@ from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
||||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||||
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
|
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django.forms.util import ErrorList
|
from django.forms.util import ErrorList
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -1484,13 +1485,15 @@ class AdminViewStringPrimaryKeyTest(TestCase):
|
||||||
def test_recentactions_link(self):
|
def test_recentactions_link(self):
|
||||||
"The link from the recent actions list referring to the changeform of the object should be quoted"
|
"The link from the recent actions list referring to the changeform of the object should be quoted"
|
||||||
response = self.client.get('/test_admin/admin/')
|
response = self.client.get('/test_admin/admin/')
|
||||||
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
|
link = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(self.pk),))
|
||||||
|
should_contain = """<a href="%s">%s</a>""" % (link, escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
|
|
||||||
def test_recentactions_without_content_type(self):
|
def test_recentactions_without_content_type(self):
|
||||||
"If a LogEntry is missing content_type it will not display it in span tag under the hyperlink."
|
"If a LogEntry is missing content_type it will not display it in span tag under the hyperlink."
|
||||||
response = self.client.get('/test_admin/admin/')
|
response = self.client.get('/test_admin/admin/')
|
||||||
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
|
link = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(self.pk),))
|
||||||
|
should_contain = """<a href="%s">%s</a>""" % (link, escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
should_contain = "Model with string primary key" # capitalized in Recent Actions
|
should_contain = "Model with string primary key" # capitalized in Recent Actions
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
|
|
Loading…
Reference in New Issue