From 042b8f956369c115536dfe7e33d9c0461dafe539 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 30 Jan 2025 13:08:34 +0100 Subject: ✨ admin: better management of Import - Item keys, import/export, links all user/imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/serializers.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'ishtar_common/serializers.py') diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py index 1469e13a1..3cbe20907 100644 --- a/ishtar_common/serializers.py +++ b/ishtar_common/serializers.py @@ -17,11 +17,12 @@ from .models_common import State, Department from archaeological_operations.models import ActType from ishtar_common.serializers_utils import ( - generic_get_results, archive_serialization, + CUSTOM_SERIALIZERS, + generic_get_results, generic_archive_files, - SERIALIZATION_VERSION, get_model_from_filename, + SERIALIZATION_VERSION, ) from archaeological_operations.serializers import ( @@ -466,7 +467,15 @@ def restore_serialized( or releasing_locks or (user and historized) ) - idx = -1 + idx = None + model_name = f"{model._meta.app_label}.{model._meta.model_name}" + if model_name in CUSTOM_SERIALIZERS: + current_serializer = CUSTOM_SERIALIZERS[model_name]() + for idx, values in enumerate(json.loads(data)): + current_serializer.save(values["fields"]) + if idx is not None: + result.append((model._meta.verbose_name, idx + 1)) + continue for idx, obj in enumerate(deserialize("json", data)): extra_attrs = {} if historized or hasattr(model, "locked"): @@ -514,6 +523,6 @@ def restore_serialized( obj.lock_user = None obj._no_move = True obj.save() - if idx >= 0: - result.append((model.__name__, idx + 1)) + if idx is not None: + result.append((model._meta.verbose_name, idx + 1)) return result -- cgit v1.2.3