diff options
-rw-r--r-- | archaeological_context_records/models.py | 17 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 13 | ||||
-rw-r--r-- | archaeological_operations/models.py | 22 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/wizard_delete_associated_to_admin_act.html | 2 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 8 |
5 files changed, 61 insertions, 1 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 179ed154d..1c0acadbc 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -1225,6 +1225,23 @@ class ContextRecord( def find_docs_q(self): return Document.objects.filter(finds__base_finds__context_record=self) + def get_deleted_data(self) -> dict: + """ + Return sub object list that will be deleted + :return: {"Sub object type": ["Sub object 1", "Sub object 2", ...]} + """ + if not self.base_finds.count(): + return {} + lbl = str(_("Base finds")) + data = {lbl: []} + for item in self.base_finds.all(): + data[lbl].append(str(item)) + for key, value in item.get_deleted_data().items(): + if key not in data: + data[key] = [] + data[key] += value + return data + def fix(self): """ Fix redundant m2m dating association (usually after imports) diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 5f2c9c8d8..398d20cf7 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -862,6 +862,19 @@ class BaseFind( def name(self): return self.label + def get_deleted_data(self) -> dict: + """ + Return sub object list that will be deleted + :return: {"Sub object type": ["Sub object 1", "Sub object 2", ...]} + """ + if self.find.count() != 1: + return {} + lbl = str(_("Finds")) + data = {lbl: []} + for item in self.find.all(): + data[lbl].append(str(item)) + return data + def post_save_basefind(sender, **kwargs): cached_label_changed(sender, **kwargs) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index eeee9e8aa..83e60866d 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1695,6 +1695,28 @@ class Operation( ) return dct + def get_deleted_data(self) -> dict: + """ + Return sub object list that will be deleted + :return: {"Sub object type": ["Sub object 1", "Sub object 2", ...]} + """ + data = {} + if self.administrative_act.count(): + lbl = str(_("Administrative act")) + data = {lbl: []} + for item in self.administrative_act.all(): + data[lbl].append(str(item)) + if self.context_record.count(): + lbl = str(_("Context record")) + data[lbl] = [] + for item in self.context_record.all(): + data[lbl].append(str(item)) + for key, value in item.get_deleted_data().items(): + if key not in data: + data[key] = [] + data[key] += value + return data + def archaeological_sites_list(self) -> list: return self.get_associated_main_item_list( "archaeological_sites", ArchaeologicalSite diff --git a/ishtar_common/templates/ishtar/wizard/wizard_delete_associated_to_admin_act.html b/ishtar_common/templates/ishtar/wizard/wizard_delete_associated_to_admin_act.html index c1284b94d..2fc84674b 100644 --- a/ishtar_common/templates/ishtar/wizard/wizard_delete_associated_to_admin_act.html +++ b/ishtar_common/templates/ishtar/wizard/wizard_delete_associated_to_admin_act.html @@ -1,5 +1,5 @@ {% extends "ishtar/wizard/delete_wizard.html" %} {% load i18n %} {% block "extra_warning" %} -<p><strong>{% trans "If any, all administrative act listed above will be deleted." %}</strong></p> +<p><strong>{% trans "If any, all related items listed above will be deleted." %}</strong></p> {% endblock %} diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 9801e596f..c4691c4f2 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1867,6 +1867,7 @@ class MultipleDeletionWizard(MultipleItemWizard): res[field.name] = (label, value, "") full_res.append(res) datas = [] + deleted_data = {} for idx, res in enumerate(full_res): data = [] for field in self.fields: @@ -1874,6 +1875,13 @@ class MultipleDeletionWizard(MultipleItemWizard): data.append(res[field]) obj = self.current_objs[idx] datas.append((f"{obj.class_verbose_name() if hasattr(obj, 'class_verbose_name') else ''} - {obj}", data)) + if hasattr(obj, "get_deleted_data"): + for key, value in obj.get_deleted_data().items(): + if key not in deleted_data: + deleted_data[key] = [] + deleted_data[key] += [(v, "", "") for v in value] + for key, value in deleted_data.items(): + datas.append((key, value)) return datas def get_context_data(self, form, **kwargs): |