Do not save empty form_config entries
All checks were successful
Tests / test (push) Successful in 30s
All checks were successful
Tests / test (push) Successful in 30s
This commit is contained in:
parent
45f17cabaa
commit
ffed6139cd
1 changed files with 16 additions and 0 deletions
|
|
@ -101,6 +101,12 @@ class ControlPlaneAdminForm(forms.ModelForm):
|
|||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
def fields_empty(fields):
|
||||
if not fields:
|
||||
return True
|
||||
return all(not field.get("controlplane_field_mapping") for field in fields)
|
||||
|
||||
|
||||
class ServiceDefinitionAdminForm(forms.ModelForm):
|
||||
api_group = forms.CharField(
|
||||
required=False,
|
||||
|
|
@ -161,6 +167,16 @@ class ServiceDefinitionAdminForm(forms.ModelForm):
|
|||
cleaned_data["api_definition"] = api_def
|
||||
|
||||
form_config = cleaned_data.get("form_config")
|
||||
|
||||
# Convert empty form_config to None (no custom form)
|
||||
if form_config:
|
||||
if not form_config.get("fieldsets") or all(
|
||||
fields_empty(fieldset.get("fields"))
|
||||
for fieldset in form_config.get("fieldsets")
|
||||
):
|
||||
form_config = None
|
||||
cleaned_data["form_config"] = None
|
||||
|
||||
if form_config:
|
||||
form_config = self._normalize_form_config_types(form_config)
|
||||
cleaned_data["form_config"] = form_config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue