1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Remove obsolete function utilities.utils.csv_format()

This commit is contained in:
Jeremy Stretch
2024-03-21 13:13:50 -04:00
parent 2a3b85a32f
commit b2e03805ab

View File

@ -1,4 +1,3 @@
import datetime
import decimal
from itertools import count, groupby
from urllib.parse import urlencode
@ -15,36 +14,6 @@ from netbox.config import get_config
from .string import title
def csv_format(data):
"""
Encapsulate any data which contains a comma within double quotes.
"""
csv = []
for value in data:
# Represent None or False with empty string
if value is None or value is False:
csv.append('')
continue
# Convert dates to ISO format
if isinstance(value, (datetime.date, datetime.datetime)):
value = value.isoformat()
# Force conversion to string first so we can check for any commas
if not isinstance(value, str):
value = '{}'.format(value)
# Double-quote the value if it contains a comma or line break
if ',' in value or '\n' in value:
value = value.replace('"', '""') # Escape double-quotes
csv.append('"{}"'.format(value))
else:
csv.append('{}'.format(value))
return ','.join(csv)
def dynamic_import(name):
"""
Dynamically import a class from an absolute path string