summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 79259b76d..859feade9 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -727,6 +727,28 @@ class Importer(object):
comment=line.comment)
return True
+ def _get_improperly_conf_error(self, model):
+ from ishtar_common.models import ImporterModel
+ cls_name = model.__module__ + "." + model.__name__
+ q = ImporterModel.objects.filter(klass=cls_name)
+ if q.count():
+ cls_name = q.all()[0].name
+ return ImproperlyConfigured(
+ unicode(self.ERRORS['improperly_configured']).format(cls_name))
+
+ def _get_does_not_exist_in_db_error(self, model, data):
+ from ishtar_common.models import ImporterModel
+ cls_name = model.__module__ + "." + model.__name__
+ q = ImporterModel.objects.filter(klass=cls_name)
+ if q.count():
+ cls_name = q.all()[0].name
+ values = u", ".join(
+ [u"{}: {}".format(k, data[k]) for k in data]
+ )
+ raise ImporterError(
+ unicode(self.ERRORS['does_not_exist_in_db']
+ ).format(cls_name, values))
+
def __init__(self, skip_lines=0, reference_header=None,
check_col_num=False, test=False, history_modifier=None,
output='silent', import_instance=None,
@@ -1025,9 +1047,7 @@ class Importer(object):
if '__force_new' in data:
if self.MODEL_CREATION_LIMIT and \
through_cls not in self.MODEL_CREATION_LIMIT:
- raise ImproperlyConfigured(
- unicode(self.ERRORS[ 'improperly_configured']).format(
- through_cls))
+ raise self._get_improperly_conf_error(through_cls)
created = data.pop('__force_new')
t_obj = through_cls.objects.create(**data)
else:
@@ -1041,12 +1061,8 @@ class Importer(object):
try:
t_obj = through_cls.objects.get(**get_data)
except through_cls.DoesNotExist:
- values = u", ".join(
- [u"{}: {}".format(k, get_data[k]) for k in get_data]
- )
- raise ImporterError(
- unicode(self.ERRORS['does_not_exist_in_db']
- ).format(through_cls, values))
+ raise self._get_does_not_exist_in_db_error(
+ through_cls, get_data)
if not created and 'defaults' in data:
for k in data['defaults']:
setattr(t_obj, k, data['defaults'][k])
@@ -1282,10 +1298,7 @@ class Importer(object):
if has_values:
if self.MODEL_CREATION_LIMIT and \
model not in self.MODEL_CREATION_LIMIT:
- raise ImproperlyConfigured(
- unicode(
- self.ERRORS['improperly_configured']
- ).format(model))
+ raise self._get_improperly_conf_error(model)
v = model.objects.create(**v)
else:
continue
@@ -1311,15 +1324,8 @@ class Importer(object):
try:
v = model.objects.get(**get_v)
except model.DoesNotExist:
- values = u", ".join(
- [u"{}: {}".format(k, get_v[k])
- for k in get_v]
- )
- raise ImporterError(
- unicode(
- self.ERRORS[
- 'does_not_exist_in_db']
- ).format(model, values))
+ raise self._get_does_not_exist_in_db_error(
+ model, get_v)
changed = False
for k in extra_fields.keys():
if extra_fields[k]:
@@ -1408,9 +1414,7 @@ class Importer(object):
new_dct.update(dct)
if self.MODEL_CREATION_LIMIT and \
cls not in self.MODEL_CREATION_LIMIT:
- raise ImproperlyConfigured(
- unicode(self.ERRORS[ 'improperly_configured']
- ).format(cls))
+ raise self._get_improperly_conf_error(cls)
obj = cls.objects.create(**new_dct)
else:
# manage UNICITY_KEYS - only level 1
@@ -1428,12 +1432,8 @@ class Importer(object):
obj = cls.objects.get(**dct)
dct['defaults'] = defaults.copy()
except cls.DoesNotExist:
- values = u", ".join(
- [u"{}: {}".format(k, dct[k]) for k in dct]
- )
- raise ImporterError(
- unicode(self.ERRORS['does_not_exist_in_db']
- ).format(cls, values))
+ raise self._get_does_not_exist_in_db_error(
+ cls, dct)
if not created and not path and self.UNICITY_KEYS:
changed = False