Issue 4334: Excluded fields are also excluded when a panel set is exp… (#4363)

* Issue 4334: Excluded fields are also excluded when a panel set is explicitly defined on a model.

* Improved notation after review with @BertrandBordage

* Incorrect field name in comment
This commit is contained in:
Lucas Moeskops 2018-03-14 19:01:32 +01:00 committed by Bertrand Bordage
parent 6126510176
commit 6b272c43e4
2 changed files with 15 additions and 1 deletions

View file

@ -63,7 +63,16 @@ def get_form_for_model(
def extract_panel_definitions_from_model_class(model, exclude=None):
if hasattr(model, 'panels'):
return model.panels
panels = model.panels
if exclude is not None:
# Filter out fields in exclude
panels = [
panel for panel in panels
if isinstance(panel, FieldPanel) and panel.field_name not in exclude
]
return panels
panels = []

View file

@ -208,6 +208,11 @@ class TestExtractPanelDefinitionsFromModelClass(TestCase):
for panel in panels:
self.assertNotEqual(panel.field_name, 'hostname')
def test_exclude_with_defined_panels(self):
Site.panels = [FieldPanel('hostname')]
panels = extract_panel_definitions_from_model_class(Site, exclude=['hostname'])
self.assertEquals([], panels)
def test_can_build_panel_list(self):
# EventPage has no 'panels' definition, so one should be derived from the field list
panels = extract_panel_definitions_from_model_class(EventPage)