Made model instance history admin view link not hard-coded. Refs #15294.
This commit is contained in:
parent
c73f2bd65c
commit
5a9e127efc
|
@ -29,7 +29,7 @@
|
||||||
{% if change %}{% if not is_popup %}
|
{% if change %}{% if not is_popup %}
|
||||||
<ul class="object-tools">
|
<ul class="object-tools">
|
||||||
{% block object-tools-items %}
|
{% block object-tools-items %}
|
||||||
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
|
<li><a href="{% url opts|admin_urlname:'history' original.pk %}" class="historylink">{% trans "History" %}</a></li>
|
||||||
{% 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%}
|
{% 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%}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -40,5 +40,12 @@
|
||||||
"fields": {
|
"fields": {
|
||||||
"description": "An action with a name suspected of being a XSS attempt"
|
"description": "An action with a name suspected of being a XSS attempt"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": "The name of an action",
|
||||||
|
"model": "admin_custom_urls.action",
|
||||||
|
"fields": {
|
||||||
|
"description": "A generic action"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,6 +10,12 @@ from .models import Action
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class AdminCustomUrlsTest(TestCase):
|
class AdminCustomUrlsTest(TestCase):
|
||||||
|
"""
|
||||||
|
Remember that:
|
||||||
|
* The Action model has a CharField PK.
|
||||||
|
* The ModelAdmin for Action customizes the add_view URL, it's
|
||||||
|
'<app name>/<model name>/!add/'
|
||||||
|
"""
|
||||||
fixtures = ['users.json', 'actions.json']
|
fixtures = ['users.json', 'actions.json']
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -20,20 +26,24 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
|
|
||||||
def testBasicAddGet(self):
|
def testBasicAddGet(self):
|
||||||
"""
|
"""
|
||||||
A smoke test to ensure GET on the add_view works.
|
Ensure GET on the add_view works.
|
||||||
"""
|
"""
|
||||||
response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/')
|
response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/')
|
||||||
self.assertIsInstance(response, TemplateResponse)
|
self.assertIsInstance(response, TemplateResponse)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def testAddWithGETArgs(self):
|
def testAddWithGETArgs(self):
|
||||||
|
"""
|
||||||
|
Ensure GET on the add_view plus specifying a field value in the query
|
||||||
|
string works.
|
||||||
|
"""
|
||||||
response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/', {'name': 'My Action'})
|
response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/', {'name': 'My Action'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'value="My Action"')
|
self.assertContains(response, 'value="My Action"')
|
||||||
|
|
||||||
def testBasicAddPost(self):
|
def testBasicAddPost(self):
|
||||||
"""
|
"""
|
||||||
A smoke test to ensure POST on add_view works.
|
Ensure POST on add_view works.
|
||||||
"""
|
"""
|
||||||
post_data = {
|
post_data = {
|
||||||
'_popup': '1',
|
'_popup': '1',
|
||||||
|
@ -47,8 +57,7 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
|
|
||||||
def testAdminUrlsNoClash(self):
|
def testAdminUrlsNoClash(self):
|
||||||
"""
|
"""
|
||||||
Test that some admin URLs work correctly. The model has a CharField
|
Test that some admin URLs work correctly.
|
||||||
PK and the add_view URL has been customized.
|
|
||||||
"""
|
"""
|
||||||
# Should get the change_view for model instance with PK 'add', not show
|
# Should get the change_view for model instance with PK 'add', not show
|
||||||
# the add_view
|
# the add_view
|
||||||
|
@ -57,17 +66,28 @@ class AdminCustomUrlsTest(TestCase):
|
||||||
self.assertContains(response, 'Change action')
|
self.assertContains(response, 'Change action')
|
||||||
|
|
||||||
# Ditto, but use reverse() to build the URL
|
# Ditto, but use reverse() to build the URL
|
||||||
path = reverse('admin:%s_action_change' % Action._meta.app_label,
|
url = reverse('admin:%s_action_change' % Action._meta.app_label,
|
||||||
args=('add',))
|
args=('add',))
|
||||||
response = self.client.get(path)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Change action')
|
self.assertContains(response, 'Change action')
|
||||||
|
|
||||||
# Should correctly get the change_view for the model instance with the
|
# Should correctly get the change_view for the model instance with the
|
||||||
# funny-looking PK
|
# funny-looking PK (the one wth a 'path/to/html/document.html' value)
|
||||||
path = reverse('admin:%s_action_change' % Action._meta.app_label,
|
url = reverse('admin:%s_action_change' % Action._meta.app_label,
|
||||||
args=("path/to/html/document.html",))
|
args=("path/to/html/document.html",))
|
||||||
response = self.client.get(path)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Change action')
|
self.assertContains(response, 'Change action')
|
||||||
self.assertContains(response, 'value="path/to/html/document.html"')
|
self.assertContains(response, 'value="path/to/html/document.html"')
|
||||||
|
|
||||||
|
def testChangeViewHistoryButton(self):
|
||||||
|
url = reverse('admin:%s_action_change' % Action._meta.app_label,
|
||||||
|
args=('The name of an action',))
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
expected_link = reverse('admin:%s_action_history' %
|
||||||
|
Action._meta.app_label,
|
||||||
|
args=('The name of an action',))
|
||||||
|
self.assertContains(response, '<a href="%s" class="historylink"' %
|
||||||
|
expected_link)
|
||||||
|
|
Loading…
Reference in New Issue