diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-06-18 03:03:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-06-18 03:03:49 +0200 |
commit | bc7a7480fefdcc4a5259fa3444ea9fcd4900ed34 (patch) | |
tree | 688e1f0b50596c14fdb42f12f05fb20b116d9b03 /ishtar_common/models.py | |
parent | 1770e38eb5cba8d8f3959d2a67384b49c9292f5f (diff) | |
download | Ishtar-bc7a7480fefdcc4a5259fa3444ea9fcd4900ed34.tar.bz2 Ishtar-bc7a7480fefdcc4a5259fa3444ea9fcd4900ed34.zip |
Import: try different encoding if the specified doesn't work
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 1f654fdf4..c1ee90df6 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1426,13 +1426,15 @@ class Import(models.Model): @property def data_table(self): with open(self.imported_file.path) as csv_file: - try: - return [line for line in unicodecsv.reader(csv_file, - encoding=self.encoding)] - except UnicodeDecodeError: - if encoding != encodings[-1]: - csv_file.seek(0) - return [] + encodings = [self.encoding] + encodings += [coding for coding, c in ENCODINGS] + for encoding in encodings: + try: + return [line for line in unicodecsv.reader(csv_file, + encoding=encoding)] + except UnicodeDecodeError: + if encoding != encodings[-1]: + csv_file.seek(0) return [] def initialize(self): |