Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deposit): page render and save a empty record #233

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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