summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/admin.py1
-rw-r--r--ishtar_common/data_importer.py6
-rw-r--r--ishtar_common/models.py16
3 files changed, 14 insertions, 9 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 8a509f1fc..c0ca88ed0 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -117,6 +117,7 @@ class ImportTargetInline(admin.TabularInline):
class ImporterColumnAdmin(admin.ModelAdmin):
list_display = ('importer_type', 'col_number', 'required')
+ list_filter = ('importer_type',)
inlines = (ImporterDuplicateFieldInline, ImportTargetInline)
admin.site.register(models.ImporterColumn, ImporterColumnAdmin)
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 2963fa680..8184f2117 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -490,7 +490,7 @@ class Importer(object):
vals.append([])
vals[idx_col].append(val)
for idx, formater in enumerate(self.line_format):
- if formater:
+ if formater and idx < len(vals):
formater.init(vals[idx], output)
def importation(self, table, initialize=True):
@@ -843,8 +843,8 @@ class Importer(object):
return data
def _format_csv_line(self, values):
- return u",".join([v and unicode(v).replace('"', '""') or u'-'
- for v in values])
+ return u'"' + u'","'.join([v and unicode(v).replace('"', '""') or u'-'
+ for v in values]) + u'"'
def _get_csv(self, rows, header=[]):
if not rows:
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 23c2f3ac7..e79eb4253 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -58,7 +58,8 @@ from ishtar_common.ooo_replace import ooo_replace
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.utils import get_cache
from ishtar_common.data_importer import Importer, ImportFormater, \
- IntegerFormater, FloatFormater, UnicodeFormater, DateFormater, TypeFormater
+ IntegerFormater, FloatFormater, UnicodeFormater, DateFormater, \
+ TypeFormater, YearFormater
def post_save_user(sender, **kwargs):
user = kwargs['instance']
@@ -1040,6 +1041,7 @@ class ImporterType(models.Model):
column.regexp_pre_filter.regexp)
formater_kwargs['duplicate_fields'] = [field.field_name
for field in column.duplicate_fields.all()]
+ formater_kwargs['required'] = column.required
formater = ImportFormater(targets, formater_types,
**formater_kwargs)
LINE_FORMAT.append(formater)
@@ -1154,7 +1156,8 @@ class Regexp(models.Model):
verbose_name = _(u"Importer - Regular expression")
verbose_name_plural = _(u"Importer - Regular expressions")
-IMPORTER_TYPES = []
+ def __unicode__(self):
+ return self.name
class ImportTarget(models.Model):
"""
@@ -1239,6 +1242,7 @@ IMPORTER_TYPES = (
('UnicodeFormater', _(u"String")),
('DateFormater', _(u"Date")),
('TypeFormater', _(u"Type")),
+ ('YearFormater', _(u"Year")),
)
IMPORTER_TYPES_DCT = {
@@ -1247,6 +1251,7 @@ IMPORTER_TYPES_DCT = {
'UnicodeFormater':UnicodeFormater,
'DateFormater':DateFormater,
'TypeFormater':TypeFormater,
+ 'YearFormater':YearFormater,
}
DATE_FORMATS = (
@@ -1269,6 +1274,7 @@ class FormaterType(models.Model):
verbose_name = _(u"Importer - Formater type")
verbose_name_plural = _(u"Importer - Formater types")
unique_together = ('formater_type', 'options', 'many_split')
+ ordering = ('formater_type', 'options')
def __unicode__(self):
return u" - ".join([unicode(dict(IMPORTER_TYPES)[self.formater_type])
@@ -1295,10 +1301,6 @@ class FormaterType(models.Model):
else:
model = import_class(self.options)
return TypeFormater(model, **kwargs)
- elif self.formater_type == 'IntegerFormater':
- return IntegerFormater(**kwargs)
- elif self.formater_type == 'FloatFormater':
- return FloatFormater(**kwargs)
elif self.formater_type == 'UnicodeFormater':
try:
return UnicodeFormater(int(self.options.strip()), **kwargs)
@@ -1306,6 +1308,8 @@ class FormaterType(models.Model):
return
elif self.formater_type == 'DateFormater':
return DateFormater(self.options, **kwargs)
+ else:
+ return IMPORTER_TYPES_DCT[self.formater_type](**kwargs)
IMPORT_STATE = (("C", _(u"Created")),
("AP", _(u"Analyse in progress")),