mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
11000 improve yaml import
This commit is contained in:
parent
d0e0c2ff8b
commit
d6e3ad098d
@ -217,13 +217,24 @@ class ImportForm(BootstrapMixin, forms.Form):
|
||||
})
|
||||
|
||||
def _clean_yaml(self, data):
|
||||
records = []
|
||||
try:
|
||||
return yaml.load_all(data, Loader=yaml.SafeLoader)
|
||||
for data in yaml.load_all(data, Loader=yaml.SafeLoader):
|
||||
if type(data) == list:
|
||||
records.extend(data)
|
||||
elif type(data) == dict:
|
||||
records.append(data)
|
||||
else:
|
||||
raise forms.ValidationError({
|
||||
self.data_field: "Invalid YAML data: data must be dictionaries or lists of dictionaries"
|
||||
})
|
||||
except yaml.error.YAMLError as err:
|
||||
raise forms.ValidationError({
|
||||
self.data_field: f"Invalid YAML data: {err}"
|
||||
})
|
||||
|
||||
return records
|
||||
|
||||
|
||||
class FilterForm(BootstrapMixin, forms.Form):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user