summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-17 10:38:58 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:24 +0100
commitc6a0150a01c61ea0682d293e1d4502c4618392b6 (patch)
tree9056e858af271dcc93c0fc6b642aa523dec2ac69 /archaeological_warehouse/models.py
parent4640d3649bd73b62dd2b1c301f7f1ebacba8fe4f (diff)
downloadIshtar-c6a0150a01c61ea0682d293e1d4502c4618392b6.tar.bz2
Ishtar-c6a0150a01c61ea0682d293e1d4502c4618392b6.zip
Container: put_document_by_external_id, put_document_by_reference
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index cb144270b..e094436e1 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -1000,18 +1000,34 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
except Warehouse.DoesNotExist:
return
- @post_importer_action
- def put_document_by_complete_identifier(self, context, value):
+ def put_document_by_key(self, value, key):
Document = apps.get_model("ishtar_common", "Document")
try:
- doc = Document.objects.get(complete_identifier=value)
+ doc = Document.objects.get(**{key: value})
except Document.DoesNotExist:
- raise ImporterError(str(_("Document with complete id: {} does not "
- "exists")).format(value))
+ raise ImporterError(str(_("Document with {}: {} does not "
+ "exists")).format(key, value))
+ except Document.MultipleObjectsReturned:
+ raise ImporterError(
+ str(_("Multiple document with {}: {}")).format(key, value))
doc.container_id = self.pk
doc.container_ref_id = self.pk
doc.skip_history_when_saving = True
doc.save()
+
+ @post_importer_action
+ def put_document_by_external_id(self, context, value):
+ self.put_document_by_key(value, "external_id")
+ put_document_by_external_id.post_save = True
+
+ @post_importer_action
+ def put_document_by_reference(self, context, value):
+ self.put_document_by_key(value, "reference")
+ put_document_by_reference.post_save = True
+
+ @post_importer_action
+ def put_document_by_complete_identifier(self, context, value):
+ self.put_document_by_key(value, "complete_identifier")
put_document_by_complete_identifier.post_save = True
def _generate_cached_division(self):