mirror of
https://github.com/django/django.git
synced 2025-11-01 12:25:37 +00:00
Fixed #8060 - Added permissions-checking for admin inlines. Thanks p.patruno for report and Stephan Jaensch for work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16934 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e2f9c11736
commit
b1b1da1eac
8 changed files with 341 additions and 72 deletions
|
|
@ -4,6 +4,18 @@ from django.contrib.admin.options import ModelAdmin
|
|||
|
||||
from models import Band, Song, SongInlineDefaultOrdering, SongInlineNewOrdering, DynOrderingBandAdmin
|
||||
|
||||
|
||||
class MockRequest(object):
|
||||
pass
|
||||
|
||||
class MockSuperUser(object):
|
||||
def has_perm(self, perm):
|
||||
return True
|
||||
|
||||
request = MockRequest()
|
||||
request.user = MockSuperUser()
|
||||
|
||||
|
||||
class TestAdminOrdering(TestCase):
|
||||
"""
|
||||
Let's make sure that ModelAdmin.queryset uses the ordering we define in
|
||||
|
|
@ -26,7 +38,7 @@ class TestAdminOrdering(TestCase):
|
|||
class.
|
||||
"""
|
||||
ma = ModelAdmin(Band, None)
|
||||
names = [b.name for b in ma.queryset(None)]
|
||||
names = [b.name for b in ma.queryset(request)]
|
||||
self.assertEqual([u'Aerosmith', u'Radiohead', u'Van Halen'], names)
|
||||
|
||||
def test_specified_ordering(self):
|
||||
|
|
@ -37,7 +49,7 @@ class TestAdminOrdering(TestCase):
|
|||
class BandAdmin(ModelAdmin):
|
||||
ordering = ('rank',) # default ordering is ('name',)
|
||||
ma = BandAdmin(Band, None)
|
||||
names = [b.name for b in ma.queryset(None)]
|
||||
names = [b.name for b in ma.queryset(request)]
|
||||
self.assertEqual([u'Radiohead', u'Van Halen', u'Aerosmith'], names)
|
||||
|
||||
def test_dynamic_ordering(self):
|
||||
|
|
@ -79,7 +91,7 @@ class TestInlineModelAdminOrdering(TestCase):
|
|||
class.
|
||||
"""
|
||||
inline = SongInlineDefaultOrdering(self.b, None)
|
||||
names = [s.name for s in inline.queryset(None)]
|
||||
names = [s.name for s in inline.queryset(request)]
|
||||
self.assertEqual([u'Dude (Looks Like a Lady)', u'Jaded', u'Pink'], names)
|
||||
|
||||
def test_specified_ordering(self):
|
||||
|
|
@ -87,5 +99,5 @@ class TestInlineModelAdminOrdering(TestCase):
|
|||
Let's check with ordering set to something different than the default.
|
||||
"""
|
||||
inline = SongInlineNewOrdering(self.b, None)
|
||||
names = [s.name for s in inline.queryset(None)]
|
||||
self.assertEqual([u'Jaded', u'Pink', u'Dude (Looks Like a Lady)'], names)
|
||||
names = [s.name for s in inline.queryset(request)]
|
||||
self.assertEqual([u'Jaded', u'Pink', u'Dude (Looks Like a Lady)'], names)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue