1
0
mirror of https://github.com/django/django.git synced 2024-12-28 12:06:22 +00:00

[1.8.x] Fixed #24333 -- Fixed admin history view crash with non-integer slug.

Backport of d64baaef3b from master
This commit is contained in:
Tim Graham 2015-02-12 13:40:23 -05:00
parent 6476fa73d3
commit 03f4e2d909
2 changed files with 11 additions and 2 deletions

View File

@ -39,7 +39,6 @@ from django.forms.models import (
from django.forms.widgets import CheckboxSelectMultiple, SelectMultiple
from django.http import Http404, HttpResponseRedirect
from django.http.response import HttpResponseBase
from django.shortcuts import get_object_or_404
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.utils import six
from django.utils.decorators import method_decorator
@ -1750,7 +1749,12 @@ class ModelAdmin(BaseModelAdmin):
from django.contrib.admin.models import LogEntry
# First check if the user can see this history.
model = self.model
obj = get_object_or_404(self.get_queryset(request), pk=unquote(object_id))
obj = self.get_object(request, unquote(object_id))
if obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
'name': force_text(model._meta.verbose_name),
'key': escape(object_id),
})
if not self.has_change_permission(request, obj):
raise PermissionDenied

View File

@ -1471,6 +1471,11 @@ class AdminViewPermissionsTest(TestCase):
self.client.get(reverse('admin:logout'))
def test_history_view_bad_url(self):
self.client.post(reverse('admin:login'), self.changeuser_login)
response = self.client.get(reverse('admin:admin_views_article_history', args=('foo',)))
self.assertEqual(response.status_code, 404)
def test_conditionally_show_add_section_link(self):
"""
The foreign key widget should only show the "add related" button if the