summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-10-26 19:10:50 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:20 +0100
commitc0976bfe3d67b6ba0b0ff6442e68ee297b172538 (patch)
tree3dfa0483278f237c4b3f0a3ad0f01365c9a80ccc
parentd62fdc84de4744ed938fabd544c08249e47be709 (diff)
downloadIshtar-c0976bfe3d67b6ba0b0ff6442e68ee297b172538.tar.bz2
Ishtar-c0976bfe3d67b6ba0b0ff6442e68ee297b172538.zip
Container: import_get_location for parent container
-rw-r--r--archaeological_warehouse/models.py17
-rw-r--r--ishtar_common/data_importer.py23
2 files changed, 30 insertions, 10 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index ecf33bb87..b51f33176 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -33,7 +33,8 @@ from django.template.defaultfilters import slugify
from ishtar_common.utils import ugettext_lazy as _, pgettext_lazy
from django.apps import apps
-from ishtar_common.data_importer import post_importer_action
+from ishtar_common.data_importer import post_importer_action, \
+ pre_importer_action
from ishtar_common.model_managers import ExternalIdManager, UUIDModelManager
from ishtar_common.models import Document, GeneralType, get_external_id, \
LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \
@@ -939,6 +940,20 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem,
def natural_key(self):
return (self.uuid, )
+ @classmethod
+ @pre_importer_action
+ def import_get_location(cls, context, value):
+ if context.get("container_type", None) and context.get(
+ "reference", None):
+ try:
+ context["location"] = Warehouse.objects.get(external_id=value)
+ return
+ except Warehouse.DoesNotExist:
+ pass
+ for k in list(context.keys()):
+ if k != "import_get_location":
+ context.pop(k)
+
def _generate_cached_label(self):
return self.precise_location
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 2595134d0..1b3f8909d 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1685,6 +1685,8 @@ class Importer(object):
try:
for attribute in list(data.keys()):
c_c_path = c_path[:]
+ if attribute not in data: # removed by previous get_field
+ continue
if not attribute:
data.pop(attribute)
continue
@@ -1821,17 +1823,20 @@ class Importer(object):
[path, q.all()[0], dct, {}])
dct['defaults'] = defaults.copy()
else:
- if not self.MODEL_CREATION_LIMIT or \
- cls in self.MODEL_CREATION_LIMIT:
- dct['defaults'] = defaults.copy()
- obj, created = cls.objects.get_or_create(**dct)
+ if not dct and not defaults:
+ obj = None
else:
- try:
- obj = cls.objects.get(**dct)
+ if not self.MODEL_CREATION_LIMIT or \
+ cls in self.MODEL_CREATION_LIMIT:
dct['defaults'] = defaults.copy()
- except cls.DoesNotExist:
- raise self._get_does_not_exist_in_db_error(
- cls, dct)
+ obj, created = cls.objects.get_or_create(**dct)
+ else:
+ try:
+ obj = cls.objects.get(**dct)
+ dct['defaults'] = defaults.copy()
+ except cls.DoesNotExist:
+ raise self._get_does_not_exist_in_db_error(
+ cls, dct)
if not created and not path and self.UNICITY_KEYS:
updated_dct = {}