1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #24089 -- Added check for when ModelAdmin.fieldsets[1]['fields'] isn't a list/tuple.

This commit is contained in:
Muthiah Annamalai 2015-01-10 11:45:05 -05:00 committed by Tim Graham
parent eeb88123e7
commit b75c707943
2 changed files with 51 additions and 0 deletions

View File

@ -130,6 +130,8 @@ class BaseModelAdminChecks(object):
id='admin.E011', id='admin.E011',
) )
] ]
elif not isinstance(fieldset[1]['fields'], (list, tuple)):
return must_be('a list or tuple', option="fieldsets[1]['fields']", obj=cls, id='admin.E008')
fields = flatten(fieldset[1]['fields']) fields = flatten(fieldset[1]['fields'])
if len(fields) != len(set(fields)): if len(fields) != len(set(fields)):

View File

@ -124,6 +124,55 @@ class SystemChecksTestCase(TestCase):
errors = ValidFormFieldsets.check(model=Song) errors = ValidFormFieldsets.check(model=Song)
self.assertEqual(errors, []) self.assertEqual(errors, [])
def test_fieldsets_fields_non_tuple(self):
"""
Tests for a tuple/list within fieldsets[1]['fields'].
"""
class NotATupleAdmin(admin.ModelAdmin):
list_display = ["pk", "title"]
list_editable = ["title"]
fieldsets = [
(None, {
"fields": "title" # not a tuple
}),
]
errors = NotATupleAdmin.check(model=Song)
expected = [
checks.Error(
"The value of 'fieldsets[1]['fields']' must be a list or tuple.",
hint=None,
obj=NotATupleAdmin,
id='admin.E008',
)
]
self.assertEqual(errors, expected)
def test_nonfirst_fieldset(self):
"""
Tests for a tuple/list within the second fieldsets[2]['fields'].
"""
class NotATupleAdmin(admin.ModelAdmin):
fieldsets = [
(None, {
"fields": ("title",)
}),
('foo', {
"fields": "author" # not a tuple
}),
]
errors = NotATupleAdmin.check(model=Song)
expected = [
checks.Error(
"The value of 'fieldsets[1]['fields']' must be a list or tuple.",
hint=None,
obj=NotATupleAdmin,
id='admin.E008',
)
]
self.assertEqual(errors, expected)
def test_exclude_values(self): def test_exclude_values(self):
""" """
Tests for basic system checks of 'exclude' option values (#12689) Tests for basic system checks of 'exclude' option values (#12689)