summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-11 20:23:41 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:24 +0100
commit838d508d64bb33f1a9dca2ee05a0d731438f78c6 (patch)
treed039b0c3e3604643b6f2c3a0fe35d292747c6053 /archaeological_warehouse
parent12c78be4ec9f89325ad80c148c92b6a306969bb5 (diff)
downloadIshtar-838d508d64bb33f1a9dca2ee05a0d731438f78c6.tar.bz2
Ishtar-838d508d64bb33f1a9dca2ee05a0d731438f78c6.zip
Add post_import action for container: put_document_by_complete_identifier
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/models.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index db08c3467..61b2e3f6d 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -45,6 +45,7 @@ from ishtar_common.models_common import GeneralType, \
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.utils import cached_label_changed, \
cached_label_and_geo_changed, get_generated_id
+from ishtar_common.data_importer import ImporterError
class DivisionContainer(DashboardFormItem):
@@ -990,7 +991,25 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
@property
def get_merge_key(self):
- return str(self.location.uuid) + "|" + self._generate_cached_division()
+ try:
+ return str(self.location.uuid) + "|" + \
+ self._generate_cached_division()
+ except Warehouse.DoesNotExist:
+ return
+
+ @post_importer_action
+ def put_document_by_complete_identifier(self, context, value):
+ Document = apps.get_model("ishtar_common", "Document")
+ try:
+ doc = Document.objects.get(complete_identifier=value)
+ except Document.DoesNotExist:
+ raise ImporterError(str(_("Document with complete id: {} does not "
+ "exists")).format(value))
+ doc.container_id = self.pk
+ doc.container_ref_id = self.pk
+ doc.skip_history_when_saving = True
+ doc.save()
+ put_document_by_complete_identifier.post_save = True
def _generate_cached_division(self):
parents = []
@@ -1371,8 +1390,11 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
if not self.responsibility_id and not self.responsibility:
if self.location_id:
self.responsibility_id = self.location_id
- if self.location:
- self.responsibility = self.location
+ else:
+ try:
+ self.responsibility = self.location
+ except Warehouse.DoesNotExist:
+ return
if self.container_type.stationary:
return
q = Container.objects.filter(index=self.index, location=self.location)