summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py21
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):