summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-09-13 14:20:01 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-09-14 13:03:11 +0200
commitaac6e0c343955155e6ff6449ca357412710c2092 (patch)
treee0549f507b3818ffb9d71fd5ddf476d09730d91a /ishtar_common/models.py
parentac1e4815e837bf14c3c9a3da74fa93a1faebac2f (diff)
downloadIshtar-aac6e0c343955155e6ff6449ca357412710c2092.tar.bz2
Ishtar-aac6e0c343955155e6ff6449ca357412710c2092.zip
✨ Imports - documents - post importer action: set_container_by_code, set_container_ref_by_code
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 063a42522..a5fcc1a91 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -5904,6 +5904,27 @@ class Document(
info.append(("rft.language", self.language.iso_code))
return '<span class="Z3988" title="{}">'.format(urlencode(info))
+ def _set_container_by_code(self, code, target='container_id'):
+ Container = apps.get_model("archaeological_warehouse", "Container")
+ try:
+ container = Container.objects.get(code=code)
+ except DoesNotExist:
+ raise ImportError(
+ str(_("Container with code {} not found.")).format(code))
+ except MultipleObjectsReturned:
+ raise ImportError(
+ str(_("Multiple containers with code {} found.")).format(code))
+ self.__class__.objects.filter(pk=self.id).update(
+ **{target: container.pk})
+
+ @post_importer_action
+ def set_container_by_code(self, context, value):
+ return self._set_container_by_code(value)
+
+ @post_importer_action
+ def set_container_ref_by_code(self, context, value):
+ return self._set_container_by_code(value, "container_ref_id")
+
def save(self, *args, **kwargs):
no_path_change = "no_path_change" in kwargs and kwargs.pop("no_path_change")
self.set_index()