Skip to content

Commit

Permalink
look for linked files by isbn (#1088)
Browse files Browse the repository at this point in the history
Co-authored-by: jbukhari <[email protected]>
  • Loading branch information
jbukhari and jbukhari authored May 25, 2023
1 parent 37f4f0b commit 78adfd3
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions dlx_rest/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,23 +542,35 @@ def get(self, collection, record_id):
return Response(record.to_mrk(), mimetype='text/plain')
elif fmt == 'mrc':
return Response(record.to_mrc(), mimetype='text/plain')

files = []

# check for files
# todo: get identifier type mapping from config
files = []
symbol = record.get_value('191', 'a') or record.get_value('191', 'z') or record.get_value('791', 'a')
isbn = record.get_value('020', 'a')
isbn = isbn.split(' ')[0] if isbn else None # field may have extra text after the isbn

for lang in ('AR', 'ZH', 'EN', 'FR', 'RU', 'ES', 'DE'):
f = File.latest_by_identifier_language(
Identifier('symbol', record.get_value('191', 'a') or record.get_value('191', 'z') or record.get_value('791', 'a')), lang
)
if f:
files.append({'mimetype': f.mimetype, 'language': lang.lower(), 'url': URL('api_file_record', record_id=f.id).to_str()})
for idtype in ([symbol, 'symbol'], [isbn, 'isbn']):
if idtype[0]:
f = File.latest_by_identifier_language(Identifier(idtype[1], idtype[0]), lang)

if f and f not in files:
files.append(f)

data = record.to_dict()
data['created'] = record.created
data['created_user'] = record.created_user
data['updated'] = record.updated
data['user'] = record.user
data['files'] = files
data['files'] = [
{
'mimetype': f.mimetype,
'language': f.languages[0].lower(),
'url': URL('api_file_record', record_id=f.id).to_str()
}
for f in files
]

meta = {
'name': 'api_record',
Expand Down

0 comments on commit 78adfd3

Please sign in to comment.