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 | 66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4 (patch) | |
| tree | a970a000cf9da411d8d7557e5825502c86cd9cfd | |
| parent | 79287474e31be5004ad6d05beb353dd481e88be5 (diff) | |
| download | Ishtar-66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4.tar.bz2 Ishtar-66ab8aa2a4d53bbd4e6d867e2bcd47e7e45c36c4.zip | |
Imports: fix skip of the first line when import file is not utf-8
| -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 [] | 
