diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-06-18 01:20:56 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-06-18 01:20:56 +0200 |
commit | 2c2303685cdab351114c511e3f937e04d342367a (patch) | |
tree | 18c73e99e1395738657ef23541f6d78583e16b7a /ishtar_common/models.py | |
parent | b39dbce58b8be027d9a9303faa506c9f426c9e1b (diff) | |
parent | a36a82f28ee691b420978e1a5b1dfd9b21580c6c (diff) | |
download | Ishtar-2c2303685cdab351114c511e3f937e04d342367a.tar.bz2 Ishtar-2c2303685cdab351114c511e3f937e04d342367a.zip |
Merge branch 'stable'
Conflicts:
ishtar_common/data_importer.py
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 15410b661..4ec4bf370 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1365,12 +1365,17 @@ IMPORT_STATE = (("C", _(u"Created")), ) IMPORT_STATE_DCT = dict(IMPORT_STATE) +ENCODINGS = [(settings.ENCODING, settings.ENCODING), + (settings.ALT_ENCODING, settings.ALT_ENCODING), + ('utf-8', 'utf-8')] class Import(models.Model): user = models.ForeignKey('IshtarUser') importer_type = models.ForeignKey(ImporterType) imported_file = models.FileField(_(u"Imported file"), upload_to="upload/imports/") + encoding = models.CharField(_(u"Encoding"), choices=ENCODINGS, + default='utf-8', max_length=15) skip_lines = models.IntegerField(_(u"Skip lines"), default=1) error_file = models.FileField(_(u"Error file"), upload_to="upload/imports/", @@ -1433,16 +1438,14 @@ class Import(models.Model): @property def data_table(self): - encodings = [settings.ENCODING, settings.ALT_ENCODING, 'utf-8'] with open(self.imported_file.path) as csv_file: - 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) - continue + try: + return [line for line in unicodecsv.reader(csv_file, + encoding=self.encoding)] + except UnicodeDecodeError: + if encoding != encodings[-1]: + csv_file.seek(0) + return [] return [] def initialize(self): |