diff options
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 |
commit | 7b883bcc1e4b34024ac624cb8162864d7b89482f (patch) | |
tree | a970a000cf9da411d8d7557e5825502c86cd9cfd /ishtar_common | |
parent | a3e22fb0ce0804f00f3e2254f755a4a0cbf2c632 (diff) | |
download | Ishtar-7b883bcc1e4b34024ac624cb8162864d7b89482f.tar.bz2 Ishtar-7b883bcc1e4b34024ac624cb8162864d7b89482f.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.py | 17 |
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 [] |