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

This commit is contained in:
Ramiro Morales 2012-08-26 17:54:49 -03:00
parent c73f2bd65c
commit 5a9e127efc
3 changed files with 38 additions and 11 deletions

View File

@ -29,7 +29,7 @@
{% if change %}{% if not is_popup %}
<ul class="object-tools">
{% 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%}
{% endblock %}
</ul>

View File

@ -40,5 +40,12 @@
"fields": {
"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"
}
}
]
]

View File

@ -10,6 +10,12 @@ from .models import Action
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
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']
def setUp(self):
@ -20,20 +26,24 @@ class AdminCustomUrlsTest(TestCase):
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/')
self.assertIsInstance(response, TemplateResponse)
self.assertEqual(response.status_code, 200)
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'})
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'value="My Action"')
def testBasicAddPost(self):
"""
A smoke test to ensure POST on add_view works.
Ensure POST on add_view works.
"""
post_data = {
'_popup': '1',
@ -47,8 +57,7 @@ class AdminCustomUrlsTest(TestCase):
def testAdminUrlsNoClash(self):
"""
Test that some admin URLs work correctly. The model has a CharField
PK and the add_view URL has been customized.
Test that some admin URLs work correctly.
"""
# Should get the change_view for model instance with PK 'add', not show
# the add_view
@ -57,17 +66,28 @@ class AdminCustomUrlsTest(TestCase):
self.assertContains(response, 'Change action')
# 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',))
response = self.client.get(path)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Change action')
# Should correctly get the change_view for the model instance with the
# funny-looking PK
path = reverse('admin:%s_action_change' % Action._meta.app_label,
# funny-looking PK (the one wth a 'path/to/html/document.html' value)
url = reverse('admin:%s_action_change' % Action._meta.app_label,
args=("path/to/html/document.html",))
response = self.client.get(path)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Change action')
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)