Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made model instance history admin view link not hard-coded. Refs #15294.

  • Loading branch information...
commit 5a9e127efc37490b2a1caa605e987a693245b5fa 1 parent c73f2bd
Ramiro Morales authored August 26, 2012
2  django/contrib/admin/templates/admin/change_form.html
@@ -29,7 +29,7 @@
29 29
 {% if change %}{% if not is_popup %}
30 30
   <ul class="object-tools">
31 31
     {% block object-tools-items %}
32  
-    <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
  32
+    <li><a href="{% url opts|admin_urlname:'history' original.pk %}" class="historylink">{% trans "History" %}</a></li>
33 33
     {% if has_absolute_url %}<li><a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
34 34
     {% endblock %}
35 35
   </ul>
9  tests/regressiontests/admin_custom_urls/fixtures/actions.json
@@ -40,5 +40,12 @@
40 40
     "fields": {
41 41
       "description": "An action with a name suspected of being a XSS attempt"
42 42
     }
  43
+  },
  44
+  {
  45
+    "pk": "The name of an action", 
  46
+    "model": "admin_custom_urls.action", 
  47
+    "fields": {
  48
+      "description": "A generic action"
  49
+    }
43 50
   }
44  
-]
  51
+]
38  tests/regressiontests/admin_custom_urls/tests.py
@@ -10,6 +10,12 @@
10 10
 
11 11
 @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
12 12
 class AdminCustomUrlsTest(TestCase):
  13
+    """
  14
+    Remember that:
  15
+    * The Action model has a CharField PK.
  16
+    * The ModelAdmin for Action customizes the add_view URL, it's
  17
+      '<app name>/<model name>/!add/'
  18
+    """
13 19
     fixtures = ['users.json', 'actions.json']
14 20
 
15 21
     def setUp(self):
@@ -20,20 +26,24 @@ def tearDown(self):
20 26
 
21 27
     def testBasicAddGet(self):
22 28
         """
23  
-        A smoke test to ensure GET on the add_view works.
  29
+        Ensure GET on the add_view works.
24 30
         """
25 31
         response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/')
26 32
         self.assertIsInstance(response, TemplateResponse)
27 33
         self.assertEqual(response.status_code, 200)
28 34
 
29 35
     def testAddWithGETArgs(self):
  36
+        """
  37
+        Ensure GET on the add_view plus specifying a field value in the query
  38
+        string works.
  39
+        """
30 40
         response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/', {'name': 'My Action'})
31 41
         self.assertEqual(response.status_code, 200)
32 42
         self.assertContains(response, 'value="My Action"')
33 43
 
34 44
     def testBasicAddPost(self):
35 45
         """
36  
-        A smoke test to ensure POST on add_view works.
  46
+        Ensure POST on add_view works.
37 47
         """
38 48
         post_data = {
39 49
             '_popup': '1',
@@ -47,8 +57,7 @@ def testBasicAddPost(self):
47 57
 
48 58
     def testAdminUrlsNoClash(self):
49 59
         """
50  
-        Test that some admin URLs work correctly. The model has a CharField
51  
-        PK and the add_view URL has been customized.
  60
+        Test that some admin URLs work correctly.
52 61
         """
53 62
         # Should get the change_view for model instance with PK 'add', not show
54 63
         # the add_view
@@ -57,17 +66,28 @@ def testAdminUrlsNoClash(self):
57 66
         self.assertContains(response, 'Change action')
58 67
 
59 68
         # Ditto, but use reverse() to build the URL
60  
-        path = reverse('admin:%s_action_change' % Action._meta.app_label,
  69
+        url = reverse('admin:%s_action_change' % Action._meta.app_label,
61 70
                 args=('add',))
62  
-        response = self.client.get(path)
  71
+        response = self.client.get(url)
63 72
         self.assertEqual(response.status_code, 200)
64 73
         self.assertContains(response, 'Change action')
65 74
 
66 75
         # Should correctly get the change_view for the model instance with the
67  
-        # funny-looking PK
68  
-        path = reverse('admin:%s_action_change' % Action._meta.app_label,
  76
+        # funny-looking PK (the one wth a 'path/to/html/document.html' value)
  77
+        url = reverse('admin:%s_action_change' % Action._meta.app_label,
69 78
                 args=("path/to/html/document.html",))
70  
-        response = self.client.get(path)
  79
+        response = self.client.get(url)
71 80
         self.assertEqual(response.status_code, 200)
72 81
         self.assertContains(response, 'Change action')
73 82
         self.assertContains(response, 'value="path/to/html/document.html"')
  83
+
  84
+    def testChangeViewHistoryButton(self):
  85
+        url = reverse('admin:%s_action_change' % Action._meta.app_label,
  86
+                args=('The name of an action',))
  87
+        response = self.client.get(url)
  88
+        self.assertEqual(response.status_code, 200)
  89
+        expected_link = reverse('admin:%s_action_history' %
  90
+                                Action._meta.app_label,
  91
+                                args=('The name of an action',))
  92
+        self.assertContains(response, '<a href="%s" class="historylink"' %
  93
+                            expected_link)

0 notes on commit 5a9e127

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