summaryrefslogtreecommitdiff
path: root/ishtar_common/models_rest.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models_rest.py')
-rw-r--r--ishtar_common/models_rest.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/ishtar_common/models_rest.py b/ishtar_common/models_rest.py
index f2b060bef..40398bca7 100644
--- a/ishtar_common/models_rest.py
+++ b/ishtar_common/models_rest.py
@@ -187,9 +187,7 @@ class ApiExternalSource(models.Model):
if not q.count():
return
sm = q.all()[0].search_model
- sheet.Name = (
- f"{sm.app_label}.{sm.model}-{model._meta.app_label}.{model.__name__.lower()}"
- )
+ sheet.Name = f"{sm.app_label}.{sm.model}-{model._meta.app_label}.{model.__name__.lower()}"
for col_number, column in enumerate(
(_("Distant key"), _("Distant label"), _("Local"))
):
@@ -198,8 +196,12 @@ class ApiExternalSource(models.Model):
cell.CharWeight = 150
cell.setString(str(column))
+ current_list = []
for idx, match in enumerate(q.all()):
cell = sheet.getCellByPosition(0, idx + 1)
+ if match.distant_slug in current_list:
+ continue
+ current_list.append(match.distant_slug)
cell.setString(match.distant_slug)
cell = sheet.getCellByPosition(1, idx + 1)
cell.setString(match.distant_label)
@@ -252,9 +254,7 @@ class ApiExternalSource(models.Model):
errors.append(str(_(f"{sheet_name} is not a correct sheet name.")))
continue
data = uno.sheet_get_data(sheet)
- base_q = ApiKeyMatch.objects.filter(
- source=self, search_model=search_model, associated_type=ct
- )
+ base_q = ApiKeyMatch.objects.filter(source=self, associated_type=ct)
model = ct.model_class()
for idx_line, line in enumerate(data):
if not idx_line: # header
@@ -262,36 +262,38 @@ class ApiExternalSource(models.Model):
distant_key, distant_label, local_name = line
q = base_q.filter(distant_slug=distant_key, distant_label=distant_label)
if not q.count():
- errors.append(
- str(
- _(
- f"{ctype} - {distant_key}, {distant_label} not referenced in the database."
+ if distant_key:
+ errors.append(
+ str(
+ _(
+ f"{ctype} - {distant_key}, {distant_label} not referenced in the database."
+ )
)
)
- )
continue
if q.filter(local_label=local_name).count():
# no change
continue
- api_key = q.all()[0]
- key_name = "slug"
- if hasattr(model, "txt_idx"):
- key_name = "txt_idx"
- q = model.objects.filter(label=local_name)
- if not q.count():
- errors.append(
- str(
- _(
- f"{ctype} - {local_name} do not exists in local database."
+ for api_key in q.all():
+ key_name = "slug"
+ if hasattr(model, "txt_idx"):
+ key_name = "txt_idx"
+ q = model.objects.filter(label=local_name)
+ if not q.count():
+ if local_name:
+ errors.append(
+ str(
+ _(
+ f"{ctype} - {local_name} do not exists in local database."
+ )
+ )
)
- )
- )
- continue
- tpe = q.all()[0]
- api_key.local_slug = getattr(tpe, key_name)
- api_key.local_label = local_name
- api_key.save()
- updated += 1
+ continue
+ tpe = q.all()[0]
+ api_key.local_slug = getattr(tpe, key_name)
+ api_key.local_label = local_name
+ api_key.save()
+ updated += 1
return {"errors": errors, "updated": updated}