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

Merge branch 'develop-2.5' into 20-physical-cabling

This commit is contained in:
Jeremy Stretch
2018-10-19 13:34:21 -04:00
28 changed files with 615 additions and 72 deletions

View File

@ -2,6 +2,7 @@ import csv
from io import StringIO
import json
import re
import sys
from django import forms
from django.conf import settings
@ -148,6 +149,11 @@ def add_blank_choice(choices):
return ((None, '---------'),) + tuple(choices)
def utf8_encoder(data):
for line in data:
yield line.encode('utf-8')
#
# Widgets
#
@ -301,7 +307,12 @@ class CSVDataField(forms.CharField):
def to_python(self, value):
records = []
reader = csv.reader(StringIO(value))
# Python 2 hack for Unicode support in the CSV reader
if sys.version_info[0] < 3:
reader = csv.reader(utf8_encoder(StringIO(value)))
else:
reader = csv.reader(StringIO(value))
# Consume and validate the first line of CSV data as column headers
headers = next(reader)