diff options
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r-- | ishtar_common/data_importer.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 673bcdde7..e8fe4e3c0 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -520,6 +520,7 @@ class StrChoiceFormater(Formater, ChoiceChecker): for value in values: new_values += r.split(value) values = new_values + TargetKey = apps.get_model("ishtar_common", "TargetKey") for value in set(values): base_value = copy.copy(value) value = self.prepare(value) @@ -558,8 +559,6 @@ class StrChoiceFormater(Formater, ChoiceChecker): else: self.equiv_dict[value] = None if self.equiv_dict[value] and self.db_target: - from ishtar_common.models import TargetKey - q = {"target": self.db_target, "key": value} query = TargetKey.objects.filter(**q) query = query.filter(self._base_target_filter(user)) @@ -578,11 +577,17 @@ class StrChoiceFormater(Formater, ChoiceChecker): except IntegrityError: pass if output == "db" and self.db_target: - from ishtar_common.models import TargetKey - for missing in self.missings: q = {"target": self.db_target, "key": missing} query = TargetKey.objects.filter(**q) + query_clean = query.filter( + associated_import__isnull=True, + associated_user__isnull=True, + associated_group__isnull=True, + is_set=False + ) + if query_clean.count(): # bad keys for this target + query_clean.delete() query = query.filter(self._base_target_filter(user)) if query.count(): continue @@ -795,7 +800,7 @@ class StrToBoolean(Formater, ChoiceChecker): self.dct[value] = None self.new_keys[value] = str(self.dct[value]) if output == "db" and self.db_target: - from ishtar_common.models import TargetKey + TargetKey = apps.get_model("ishtar_common", "TargetKey") for missing in self.missings: try: |