mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #764: Encapsulate in double quotes values containing commas when exporting to CSV
This commit is contained in:
15
netbox/utilities/utils.py
Normal file
15
netbox/utilities/utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
def csv_format(data):
|
||||
"""
|
||||
Encapsulate any data which contains a comma within double quotes.
|
||||
"""
|
||||
csv = []
|
||||
for d in data:
|
||||
if d in [None, False]:
|
||||
csv.append(u'')
|
||||
elif type(d) not in (str, unicode):
|
||||
csv.append(u'{}'.format(d))
|
||||
elif u',' in d:
|
||||
csv.append(u'"{}"'.format(d))
|
||||
else:
|
||||
csv.append(d)
|
||||
return u','.join(csv)
|
Reference in New Issue
Block a user