Fixed #18051 -- Allowed admin fieldsets to contain lists
Thanks Ricardo di Virgilio for the report, Mateus Gondim for the patch and Nick Sandford for the review.
This commit is contained in:
parent
c6e0dedbdb
commit
013db6ba85
|
@ -88,8 +88,7 @@ def flatten_fieldsets(fieldsets):
|
||||||
field_names = []
|
field_names = []
|
||||||
for name, opts in fieldsets:
|
for name, opts in fieldsets:
|
||||||
for field in opts['fields']:
|
for field in opts['fields']:
|
||||||
# type checking feels dirty, but it seems like the best way here
|
if isinstance(field, (list, tuple)):
|
||||||
if type(field) == tuple:
|
|
||||||
field_names.extend(field)
|
field_names.extend(field)
|
||||||
else:
|
else:
|
||||||
field_names.append(field)
|
field_names.append(field)
|
||||||
|
|
|
@ -5,8 +5,8 @@ from datetime import datetime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin import helpers
|
from django.contrib.admin import helpers
|
||||||
from django.contrib.admin.util import (display_for_field, label_for_field,
|
from django.contrib.admin.util import (display_for_field, flatten_fieldsets,
|
||||||
lookup_field, NestedObjects)
|
label_for_field, lookup_field, NestedObjects)
|
||||||
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
|
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.db import models, DEFAULT_DB_ALIAS
|
from django.db import models, DEFAULT_DB_ALIAS
|
||||||
|
@ -300,3 +300,21 @@ class UtilTests(unittest.TestCase):
|
||||||
'<label for="id_text" class="required inline">&text:</label>')
|
'<label for="id_text" class="required inline">&text:</label>')
|
||||||
self.assertEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
|
self.assertEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
|
||||||
'<label for="id_cb" class="vCheckboxLabel required inline">&cb</label>')
|
'<label for="id_cb" class="vCheckboxLabel required inline">&cb</label>')
|
||||||
|
|
||||||
|
def test_flatten_fieldsets(self):
|
||||||
|
"""
|
||||||
|
Regression test for #18051
|
||||||
|
"""
|
||||||
|
fieldsets = (
|
||||||
|
(None, {
|
||||||
|
'fields': ('url', 'title', ('content', 'sites'))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
|
||||||
|
|
||||||
|
fieldsets = (
|
||||||
|
(None, {
|
||||||
|
'fields': ['url', 'title', ['content', 'sites'])
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
|
||||||
|
|
Loading…
Reference in New Issue