From 3176e8cecfbf8e0e4dbcff9d5f8c19f164198010 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 10 Apr 2020 16:34:33 +0200 Subject: Fix merge candidate for containers --- archaeological_warehouse/models.py | 6 ++++++ .../templates/ishtar/wizard/wizard_container.html | 17 +++++++++++++++++ .../ishtar/wizard/wizard_containerlocalisation.html | 17 ----------------- ishtar_common/models.py | 4 +++- 4 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 archaeological_warehouse/templates/ishtar/wizard/wizard_container.html delete mode 100644 archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 53e50976d..8d2a3fb71 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -482,6 +482,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, SearchVectorConfig("division__reference"), SearchVectorConfig("division__division__division__label"), ] + PARENT_SEARCH_VECTORS = ["parent"] # search parameters EXTRA_REQUEST_KEYS = { @@ -704,6 +705,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, verbose_name=_("Main image"), blank=True, null=True) DISABLE_POLYGONS = False + MERGE_ATTRIBUTE = "get_cached_division" class Meta: verbose_name = _("Container") @@ -751,6 +753,10 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, cached_label = " - ".join(items) return cached_label + @property + def get_cached_division(self): + return self._generate_cached_division() + def _generate_cached_division(self): parents = [] parent = self.parent diff --git a/archaeological_warehouse/templates/ishtar/wizard/wizard_container.html b/archaeological_warehouse/templates/ishtar/wizard/wizard_container.html new file mode 100644 index 000000000..4d0a63c17 --- /dev/null +++ b/archaeological_warehouse/templates/ishtar/wizard/wizard_container.html @@ -0,0 +1,17 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n %} +{% block form_head %} +{% if not wizard.form.fields %} +

+ + {% trans "No division set for this warehouse. Define at least one division to localise containers in this warehouse." %}
+ {{wizard.form.warehouse}} + + + + + + +

+{% endif %} +{% endblock %} diff --git a/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html b/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html deleted file mode 100644 index 4d0a63c17..000000000 --- a/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends "ishtar/wizard/default_wizard.html" %} -{% load i18n %} -{% block form_head %} -{% if not wizard.form.fields %} -

- - {% trans "No division set for this warehouse. Define at least one division to localise containers in this warehouse." %}
- {{wizard.form.warehouse}} - - - - - - -

-{% endif %} -{% endblock %} diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 071b05598..9011c4638 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4228,6 +4228,7 @@ class Merge(models.Model): # 1 for one word similarity, 2 for two word similarity, etc. MERGE_CLEMENCY = None EMPTY_MERGE_KEY = '--' + MERGE_ATTRIBUTE = "name" class Meta: abstract = True @@ -4235,7 +4236,8 @@ class Merge(models.Model): def generate_merge_key(self): if self.archived: return - self.merge_key = slugify(self.name if self.name else '') + merge_attr = getattr(self, self.MERGE_ATTRIBUTE) + self.merge_key = slugify(merge_attr if merge_attr else '') if not self.merge_key: self.merge_key = self.EMPTY_MERGE_KEY self.merge_key = self.merge_key -- cgit v1.2.3