Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 013db6ba85fb880bd1f9a5ad2e91dc5c1efe197c 1 parent c6e0ded
Claude Paroz authored January 21, 2013
3  django/contrib/admin/util.py
@@ -88,8 +88,7 @@ def flatten_fieldsets(fieldsets):
88 88
     field_names = []
89 89
     for name, opts in fieldsets:
90 90
         for field in opts['fields']:
91  
-            # type checking feels dirty, but it seems like the best way here
92  
-            if type(field) == tuple:
  91
+            if isinstance(field, (list, tuple)):
93 92
                 field_names.extend(field)
94 93
             else:
95 94
                 field_names.append(field)
22  tests/regressiontests/admin_util/tests.py
@@ -5,8 +5,8 @@
5 5
 from django.conf import settings
6 6
 from django.contrib import admin
7 7
 from django.contrib.admin import helpers
8  
-from django.contrib.admin.util import (display_for_field, label_for_field,
9  
-    lookup_field, NestedObjects)
  8
+from django.contrib.admin.util import (display_for_field, flatten_fieldsets,
  9
+    label_for_field, lookup_field, NestedObjects)
10 10
 from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
11 11
 from django.contrib.sites.models import Site
12 12
 from django.db import models, DEFAULT_DB_ALIAS
@@ -300,3 +300,21 @@ class MyForm(forms.Form):
300 300
                          '<label for="id_text" class="required inline">&amp;text:</label>')
301 301
         self.assertEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
302 302
                          '<label for="id_cb" class="vCheckboxLabel required inline">&amp;cb</label>')
  303
+
  304
+    def test_flatten_fieldsets(self):
  305
+        """
  306
+        Regression test for #18051
  307
+        """
  308
+        fieldsets = (
  309
+            (None, {
  310
+                'fields': ('url', 'title', ('content', 'sites'))
  311
+            }),
  312
+        )
  313
+        self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
  314
+
  315
+        fieldsets = (
  316
+            (None, {
  317
+                'fields': ['url', 'title', ['content', 'sites'])
  318
+            }),
  319
+        )
  320
+        self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])

0 notes on commit 013db6b

Please sign in to comment.
Something went wrong with that request. Please try again.