From a1ea89a00b538c416aecec1e49894e12505e3450 Mon Sep 17 00:00:00 2001 From: Philipp Gualdi Date: Wed, 30 Oct 2024 14:07:17 +0000 Subject: [PATCH] fix(deposit): page render and save a empty record --- .../resources/deserializers/schema.py | 12 ++++++++---- .../resources/serializers/deposit/schema.py | 15 +++++++++------ invenio_records_marc21/ui/theme/deposit.py | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/invenio_records_marc21/resources/deserializers/schema.py b/invenio_records_marc21/resources/deserializers/schema.py index 043111c8..14108a0e 100644 --- a/invenio_records_marc21/resources/deserializers/schema.py +++ b/invenio_records_marc21/resources/deserializers/schema.py @@ -31,6 +31,12 @@ class Meta: def load_metadata(self, value): """Load metadata.""" fields = {} + metadata = { + "leader": value["leader"], + } + + if "fields" not in value: + return metadata for field in value["fields"]: if int(field["id"]) < 10: @@ -50,10 +56,8 @@ def load_metadata(self, value): "subfields": subfields, } ) - return { - "fields": fields, - "leader": value["leader"], - } + metadata["fields"] = fields + return metadata @pre_load def remove(self, data, **kwargs): diff --git a/invenio_records_marc21/resources/serializers/deposit/schema.py b/invenio_records_marc21/resources/serializers/deposit/schema.py index f038e369..442057fb 100644 --- a/invenio_records_marc21/resources/serializers/deposit/schema.py +++ b/invenio_records_marc21/resources/serializers/deposit/schema.py @@ -20,8 +20,14 @@ class MetadataDepositField(Field): def _serialize(self, value, attr, obj, **kwargs): """Serialize metadata field.""" - fields_ui = [] + record = { + "fields": [], + "leader": value.get("leader"), + } + if "fields" not in value: + return record + fields_ui = [] for category, fields in value["fields"].items(): if isinstance(fields, str): obj = { @@ -45,11 +51,8 @@ def _serialize(self, value, attr, obj, **kwargs): } fields_ui.append(obj) - - return { - "fields": fields_ui, - "leader": value.get("leader"), - } + record["fields"] = fields_ui + return record class Marc21DepositSchema(Marc21Schema): diff --git a/invenio_records_marc21/ui/theme/deposit.py b/invenio_records_marc21/ui/theme/deposit.py index a8192a28..07fe57e3 100644 --- a/invenio_records_marc21/ui/theme/deposit.py +++ b/invenio_records_marc21/ui/theme/deposit.py @@ -20,7 +20,7 @@ def empty_record(): """Create an empty record.""" record = dump_empty(Marc21RecordSchema) - record["metadata"] = "00000nam a2200000zca4500" + record["metadata"] = {"leader": "00000nam a2200000zca4500", "fields": []} record["access"] = {"record": "public", "files": "public"} record["files"] = {"enabled": True} record["status"] = "draft"