diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/data_importer.py | 23 | ||||
-rw-r--r-- | ishtar_common/migrations/0061_auto_20180813_1729.py | 25 | ||||
-rw-r--r-- | ishtar_common/models.py | 2 |
3 files changed, 45 insertions, 5 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index defa5b091..af8cc461e 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1068,6 +1068,7 @@ class Importer(object): sys.stdout.write("\n") results = [] for idx_line, line in enumerate(table): + self.idx_line = idx_line if line_to_process is not None: if line_to_process != idx_line: continue @@ -1381,6 +1382,8 @@ class Importer(object): many_values = data.pop(attribute) if hasattr(field_object, 'rel'): model = field_object.rel.to + elif hasattr(field_object, 'related_model'): + model = field_object.related_model elif hasattr(field_object, 'to'): model = field_object.to elif hasattr(field_object, 'model'): @@ -1489,6 +1492,12 @@ class Importer(object): unicode( _(u"Importer configuration error: " u"\"{}\".")).format(e.message)) + except Exception as e: + msg = unicode( + _(u"Import error: {} - \"{}\".") + ).format(model, e.message.decode('utf-8')) + e.message = msg + raise e else: get_v = v.copy() if 'defaults' in get_v: @@ -1566,8 +1575,11 @@ class Importer(object): _(u"Importer configuration error: field \"{}\" does not exist " u"for {}.")).format(attribute, cls._meta.verbose_name)) if field_object.many_to_many: - m2ms += self._get_field_m2m(attribute, data, c_path, - new_created, field_object) + try: + m2ms += self._get_field_m2m(attribute, data, c_path, + new_created, field_object) + except Exception as e: + self.errors.append((self.idx_line, None, e.message)) return if not hasattr(field_object, 'rel') or not field_object.rel: return @@ -1664,7 +1676,7 @@ class Importer(object): defaults = {} if path in self._defaults: for k in self._defaults[path]: - if k not in data or not data[k]: + if (k not in data or not data[k]) and self._defaults[path][k]: defaults[k] = self._defaults[path][k] if 'history_modifier' in create_dict: @@ -1698,7 +1710,10 @@ class Importer(object): for k in dct.keys(): if k not in self.UNICITY_KEYS \ and k != 'defaults': - defaults[k] = dct.pop(k) + if dct[k]: + defaults[k] = dct.pop(k) + else: + dct.pop(k) if self.simulate: q = cls.objects.filter(**dct) diff --git a/ishtar_common/migrations/0061_auto_20180813_1729.py b/ishtar_common/migrations/0061_auto_20180813_1729.py new file mode 100644 index 000000000..2390f160d --- /dev/null +++ b/ishtar_common/migrations/0061_auto_20180813_1729.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-13 17:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0060_auto_20180613_1848'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='imports', + field=models.ManyToManyField(blank=True, related_name='imported_ishtar_common_document', to='ishtar_common.Import'), + ), + migrations.AlterField( + model_name='document', + name='item_number', + field=models.IntegerField(default=1, verbose_name='Number of items'), + ), + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 13e91a680..86b74693f 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3107,7 +3107,7 @@ post_save.connect(post_save_cache, sender=LicenseType) post_delete.connect(post_save_cache, sender=LicenseType) -class Document(OwnPerms, ImageModel, FullSearch): +class Document(OwnPerms, ImageModel, FullSearch, Imported): # order is important: put the image in the first match found # other will be symbolic links RELATED_MODELS = [ |