1
0
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:
Jeremy Stretch
2017-01-04 10:47:00 -05:00
parent 8154ae3685
commit 52567c4ade
5 changed files with 80 additions and 61 deletions

15
netbox/utilities/utils.py Normal file
View 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)