summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index ed7cae234..4bea24ab5 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -675,22 +675,28 @@ class GeneralType(Cached, models.Model):
self.generate_key(force=True)
return obj
- def add_key(self, key, force=False, importer=None, group=None, user=None):
+ def add_key(self, key, force=False, importer_type=None, ishtar_import=None,
+ group=None, user=None):
ItemKey = apps.get_model("ishtar_common", "ItemKey")
content_type = ContentType.objects.get_for_model(self.__class__)
if (
- not importer
+ not ishtar_import
and not force
and ItemKey.objects.filter(key=key, content_type=content_type).count()
):
return
filtr = {"key": key, "content_type": content_type}
- if group:
+ if importer_type:
+ filtr["importer_type"] = importer_type
+ elif group:
filtr["group"] = group
+ filtr["importer_type"] = ishtar_import.importer_type if ishtar_import else None
elif user:
filtr["user"] = user
+ filtr["importer_type"] = ishtar_import.importer_type if ishtar_import else None
else:
- filtr["importer"] = importer
+ filtr["ishtar_import"] = ishtar_import
+ filtr["importer_type"] = ishtar_import.importer_type if ishtar_import else None
if force:
ItemKey.objects.filter(**filtr).exclude(object_id=self.pk).delete()
filtr["object_id"] = self.pk
@@ -700,18 +706,23 @@ class GeneralType(Cached, models.Model):
for key in (slugify(self.label), self.txt_idx):
self.add_key(key)
- def get_keys(self, importer):
+ def get_keys(self, current_import):
+ importer_type = current_import.importer_type
ItemKey = apps.get_model("ishtar_common", "ItemKey")
keys = [self.txt_idx]
content_type = ContentType.objects.get_for_model(self.__class__)
base_q = Q(content_type=content_type, object_id=self.pk)
- subquery = Q(importer__isnull=True, user__isnull=True, group__isnull=True)
- subquery |= Q(user__isnull=True, group__isnull=True, importer=importer)
- if importer.user:
- subquery |= Q(user=importer.user, group__isnull=True, importer=importer)
- if importer.associated_group:
+ subquery = Q(importer_type__isnull=True, user__isnull=True,
+ group__isnull=True)
+ subquery |= Q(user__isnull=True, group__isnull=True,
+ importer_type=importer_type)
+ if current_import.user:
+ subquery |= Q(user=current_import.user, group__isnull=True,
+ importer_type=importer_type)
+ if current_import.associated_group:
subquery |= Q(
- user__isnull=True, group=importer.associated_group, importer=importer
+ user__isnull=True, group=current_import.associated_group,
+ importer_type=importer_type
)
q = ItemKey.objects.filter(base_q & subquery)
for ik in q.exclude(key=self.txt_idx).all():