Skip to content

Commit

Permalink
fix(deposit): page render and save a empty record
Browse files Browse the repository at this point in the history
  • Loading branch information
philippgualdi committed Oct 31, 2024
1 parent 4c69ee8 commit b04e184
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 8 additions & 4 deletions invenio_records_marc21/resources/deserializers/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
15 changes: 9 additions & 6 deletions invenio_records_marc21/resources/serializers/deposit/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion invenio_records_marc21/ui/theme/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def empty_record():
"""Create an empty record."""
record = dump_empty(Marc21RecordSchema)
record["metadata"] = "<record><leader>00000nam a2200000zca4500</leader></record>"
record["metadata"] = {"leader": "00000nam a2200000zca4500", "fields": []}
record["access"] = {"record": "public", "files": "public"}
record["files"] = {"enabled": True}
record["status"] = "draft"
Expand Down

0 comments on commit b04e184

Please sign in to comment.