mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
11617 special case DeviceType and ModuleType
This commit is contained in:
parent
b415c157cc
commit
b8d7c8bc0d
@ -15,6 +15,7 @@ from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django_tables2.export import TableExport
|
||||
|
||||
from dcim.forms.bulk_import import DeviceTypeImportForm, ModuleTypeImportForm
|
||||
from extras.models import ExportTemplate
|
||||
from extras.signals import clear_webhooks
|
||||
from utilities.error_handlers import handle_protectederror
|
||||
@ -406,7 +407,7 @@ class BulkImportView(GetReturnURLMixin, BaseMultiObjectView):
|
||||
]
|
||||
if not headers:
|
||||
headers = headers_to_dict(list(record.keys()))
|
||||
validate_import_headers(headers, form_fields, required_fields)
|
||||
validate_import_headers(headers, form_fields, required_fields, allow_extra_columns=isinstance(model_form, (DeviceTypeImportForm, ModuleTypeImportForm)))
|
||||
|
||||
# When updating, omit all form fields other than those specified in the record. (No
|
||||
# fields are required when modifying an existing object.)
|
||||
|
@ -251,7 +251,7 @@ def parse_csv(reader):
|
||||
return headers, records
|
||||
|
||||
|
||||
def validate_import_headers(headers, fields, required_fields):
|
||||
def validate_import_headers(headers, fields, required_fields, allow_extra_columns=False):
|
||||
"""
|
||||
Validate that parsed csv data conforms to the object's available fields. Raise validation errors
|
||||
if parsed csv data contains invalid headers or does not contain required headers.
|
||||
@ -262,7 +262,7 @@ def validate_import_headers(headers, fields, required_fields):
|
||||
if field == "id":
|
||||
is_update = True
|
||||
continue
|
||||
if field not in fields:
|
||||
if (not allow_extra_columns) and (field not in fields):
|
||||
raise forms.ValidationError(f'Unexpected column header "{field}" found.')
|
||||
if to_field and not hasattr(fields[field], 'to_field_name'):
|
||||
raise forms.ValidationError(f'Column "{field}" is not a related object; cannot use dots')
|
||||
|
Loading…
Reference in New Issue
Block a user