mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Include tab as a supported delimiting character for auto-detection
This commit is contained in:
parent
cce89a55fb
commit
f14f2fa5f0
@ -105,18 +105,16 @@ class BulkImportForm(BootstrapMixin, SyncedDataMixin, forms.Form):
|
||||
"""
|
||||
Clean CSV-formatted data. The first row will be treated as column headers.
|
||||
"""
|
||||
|
||||
if delimiter == CSVDelimiterChoices.AUTO:
|
||||
# Determine the CSV dialect
|
||||
if delimiter == CSVDelimiterChoices.AUTO:
|
||||
# This uses a rough heuristic to detect the CSV dialect based on the presence of supported delimiting
|
||||
# characters. If the data is malformed, we'll fall back to the default Excel dialect.
|
||||
delimiters = ''.join(CSVDelimiterChoices.values()[1:]) # Skip "auto"
|
||||
try:
|
||||
# This uses a rough heuristic to detect the CSV dialect. If the data is malformed, we'll fall back to
|
||||
# the default Excel dialect. Note that delimiter can only be one character.
|
||||
dialect = csv.Sniffer().sniff(
|
||||
data.strip(), delimiters=''.join([CSVDelimiterChoices.COMMA, CSVDelimiterChoices.SEMICOLON])
|
||||
)
|
||||
dialect = csv.Sniffer().sniff(data.strip(), delimiters=delimiters)
|
||||
except csv.Error:
|
||||
dialect = csv.excel
|
||||
elif delimiter in [CSVDelimiterChoices.COMMA, CSVDelimiterChoices.SEMICOLON]:
|
||||
elif delimiter in (CSVDelimiterChoices.COMMA, CSVDelimiterChoices.SEMICOLON):
|
||||
dialect = csv.excel
|
||||
dialect.delimiter = delimiter
|
||||
elif delimiter == CSVDelimiterChoices.TAB:
|
||||
|
Loading…
Reference in New Issue
Block a user