summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-20 17:07:27 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-20 17:07:27 +0200
commit66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4 (patch)
treea970a000cf9da411d8d7557e5825502c86cd9cfd /ishtar_common
parent79287474e31be5004ad6d05beb353dd481e88be5 (diff)
downloadIshtar-66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4.tar.bz2
Ishtar-66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4.zip
Imports: fix skip of the first line when import file is not utf-8
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 5c84447a4..e49044cfd 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2464,20 +2464,21 @@ class Import(models.Model):
tmpdir = tempfile.mkdtemp(prefix='tmp-ishtar-')
imported_file = z.extract(filename, tmpdir)
- with open(imported_file) as csv_file:
- encodings = [self.encoding]
- encodings += [coding for coding, c in ENCODINGS]
- for encoding in encodings:
- try:
+ encodings = [self.encoding]
+ encodings += [coding for coding, c in ENCODINGS
+ if coding != self.encoding]
+ for encoding in encodings:
+ try:
+ with open(imported_file) as csv_file:
vals = [line
for line in unicodecsv.reader(csv_file,
encoding=encoding)]
if tmpdir:
shutil.rmtree(tmpdir)
+ print(encoding, imported_file, vals[0])
return vals
- except UnicodeDecodeError:
- if encoding != encodings[-1]:
- csv_file.seek(0)
+ except UnicodeDecodeError:
+ print(encoding, encodings)
if tmpdir:
shutil.rmtree(tmpdir)
return []