diff options
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r-- | ishtar_common/models_imports.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index b4749fc2c..d64b8441c 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -271,7 +271,7 @@ def get_associated_model(parent_model, keys): OBJECT_CLS = parent_model fields = get_model_fields(OBJECT_CLS) for idx, item in enumerate(keys): - if item in (u"-", u""): + if item in ("-", ""): model = None elif not idx: if item not in fields: @@ -287,6 +287,14 @@ def get_associated_model(parent_model, keys): if type(field) == ModelBase: model = field else: + if not model: + raise ImporterError( + str(_("Importer configuration error: " + "\"{}\" is not available for \"{}\"." + " Check your default and column " + "configuration")).format( + "__".join(keys[1:]), + OBJECT_CLS.__name__)) return get_associated_model(model, keys[1:]) return model @@ -576,6 +584,8 @@ class ImportTarget(models.Model): @property def associated_model(self): + if self.target.startswith("data__"): + return try: return get_associated_model( self.column.importer_type.associated_models.klass, @@ -631,9 +641,9 @@ class TargetKey(models.Model): (associated_import, associated_user and associated_group are empty). """ target = models.ForeignKey(ImportTarget, related_name='keys') - key = models.TextField(_(u"Key")) - value = models.TextField(_(u"Value"), blank=True, null=True) - is_set = models.BooleanField(_(u"Is set"), default=False) + key = models.TextField(_("Key")) + value = models.TextField(_("Value"), blank=True, null=True) + is_set = models.BooleanField(_("Is set"), default=False) associated_import = models.ForeignKey('Import', blank=True, null=True) associated_user = models.ForeignKey('IshtarUser', blank=True, null=True) associated_group = models.ForeignKey(TargetKeyGroup, blank=True, null=True) @@ -671,10 +681,10 @@ class TargetKey(models.Model): obj = super(TargetKey, self).save(*args, **kwargs) if not self.value: return obj + v = None associated_model = self.target.associated_model if associated_model and hasattr(self.target.associated_model, "add_key"): - v = None # pk is given try: v = self.target.associated_model.objects.get( |