Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.6.x] Fixed LogEntry.get_admin_url() for non-existent models.

Regression introduced by [369b6fa]; refs #18169.

Backport of 1b47508 from master
  • Loading branch information...
commit 4e7745cc1c89a0c464b752e6da7c1fe7bce948d0 1 parent 4f8fb19
PetrDlouhy authored August 01, 2013 timgraham committed August 02, 2013
7  django/contrib/admin/models.py
@@ -4,7 +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
+from django.core.urlresolvers import reverse, NoReverseMatch
8 8
 from django.utils.translation import ugettext, ugettext_lazy as _
9 9
 from django.utils.encoding import smart_text
10 10
 from django.utils.encoding import python_2_unicode_compatible
@@ -74,5 +74,8 @@ def get_admin_url(self):
74 74
         """
75 75
         if self.content_type and self.object_id:
76 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),))
  77
+            try:
  78
+                return reverse(url_name, args=(quote(self.object_id),))
  79
+            except NoReverseMatch:
  80
+                pass
78 81
         return None
11  tests/admin_views/tests.py
@@ -1525,6 +1525,17 @@ def test_recentactions_without_content_type(self):
1525 1525
         self.assertEqual(counted_presence_before - 1,
1526 1526
                           counted_presence_after)
1527 1527
 
  1528
+    def test_logentry_get_admin_url(self):
  1529
+        "LogEntry.get_admin_url returns a URL to edit the entry's object or None for non-existent (possibly deleted) models"
  1530
+        log_entry_name = "Model with string primary key"  # capitalized in Recent Actions
  1531
+        logentry = LogEntry.objects.get(content_type__name__iexact=log_entry_name)
  1532
+        model = "modelwithstringprimarykey"
  1533
+        desired_admin_url = "/test_admin/admin/admin_views/%s/%s/" % (model, escape(iri_to_uri(urlquote(quote(self.pk)))))
  1534
+        self.assertEqual(logentry.get_admin_url(), desired_admin_url)
  1535
+
  1536
+        logentry.content_type.model = "non-existent"
  1537
+        self.assertEqual(logentry.get_admin_url(), None)
  1538
+
1528 1539
     def test_deleteconfirmation_link(self):
1529 1540
         "The link from the delete confirmation page referring back to the changeform of the object should be quoted"
1530 1541
         response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk))

0 notes on commit 4e7745c

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