Remove special case removing FieldPanels from PanelGroup if they're excluded from the form

The is_shown method on FieldPanel now detects this case instead.
pull/8283/head
Matt Westcott 2022-03-14 13:58:06 +00:00 zatwierdzone przez Matt Westcott
rodzic 470d39e1fe
commit fae68ad8c8
1 zmienionych plików z 6 dodań i 11 usunięć

Wyświetl plik

@ -416,17 +416,7 @@ class PanelGroup(Panel):
self.children = [child.bind_to(request=self.request) for child in self.children] self.children = [child.bind_to(request=self.request) for child in self.children]
def on_form_bound(self): def on_form_bound(self):
children = [] self.children = [child.bind_to(form=self.form) for child in self.children]
for child in self.children:
if isinstance(child, FieldPanel):
if self.form._meta.exclude:
if child.field_name in self.form._meta.exclude:
continue
if self.form._meta.fields:
if child.field_name not in self.form._meta.fields:
continue
children.append(child.bind_to(form=self.form))
self.children = children
def render(self): def render(self):
return mark_safe(render_to_string(self.template, {"self": self})) return mark_safe(render_to_string(self.template, {"self": self}))
@ -599,6 +589,10 @@ class FieldPanel(Panel):
return opts return opts
def is_shown(self): def is_shown(self):
if self.form is not None and self.bound_field is None:
# this field is missing from the form
return False
if ( if (
self.permission self.permission
and self.request and self.request
@ -722,6 +716,7 @@ class FieldPanel(Panel):
try: try:
self.bound_field = self.form[self.field_name] self.bound_field = self.form[self.field_name]
except KeyError: except KeyError:
self.bound_field = None
return return
if self.heading: if self.heading: