mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Force validation of individual objects within a MultiObjectField
This commit is contained in:
@ -570,6 +570,14 @@ class MultiObjectField(forms.Field):
|
||||
if value is None:
|
||||
return list()
|
||||
|
||||
for i, obj_data in enumerate(value, start=1):
|
||||
form = self.form(obj_data)
|
||||
if not form.is_valid():
|
||||
errors = [
|
||||
"Object {} {}: {}".format(i, field, errors) for field, errors in form.errors.items()
|
||||
]
|
||||
raise forms.ValidationError(errors)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
|
@ -443,9 +443,14 @@ class ObjectImportView(GetReturnURLMixin, View):
|
||||
return redirect(self.get_return_url(request, obj))
|
||||
|
||||
else:
|
||||
|
||||
# Replicate model form errors for display
|
||||
for field, err in model_form.errors.items():
|
||||
form.add_error(None, "{}: {}".format(field, err))
|
||||
for field, errors in model_form.errors.items():
|
||||
for err in errors:
|
||||
if field == '__all__':
|
||||
form.add_error(None, err)
|
||||
else:
|
||||
form.add_error(None, "{}: {}".format(field, err))
|
||||
|
||||
return render(request, self.template_name, {
|
||||
'form': form,
|
||||
|
Reference in New Issue
Block a user