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

landing-page: add additional titles #185

Merged
Merged
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
22 changes: 20 additions & 2 deletions invenio_records_marc21/resources/serializers/ui/fields/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"""Metadata field for marc21 records."""
import re
from contextlib import suppress
from dataclasses import dataclass
from typing import Dict, List

Expand Down Expand Up @@ -103,7 +104,8 @@ def get_values(

values = []
for field in fields:
values += field.get(subfield_notation)
with suppress(KeyError):
values += field.get(subfield_notation)

return values

Expand Down Expand Up @@ -174,8 +176,24 @@ def get_authors(self, fields):
return authors

def get_titles(self, fields):
"""Get title."""
"""Get title.

The normal separator between the main title and the additional
title is ':'.

There are special cases where the 245 subfield 'b' has a '='
in front. If this happens the separator between 'a' and 'b'
should not be ':' because there is already the '=' as a
separator.
"""
titles = fields.get_values("245", subfield_notation="a")
additional_titles = fields.get_values("245", subfield_notation="b")

if len(additional_titles) > 0 and additional_titles[0][0] != "=":
titles += [":"]

titles += additional_titles

return [re.sub(r"[<>]", "", title) for title in titles]

def get_published_month(self, fields):
Expand Down