display isni bio with existing author name

If an existing author has an isni on record and it matches an author from the isni api call,
display the isni short description to aid with identifying the appropriate author.
This commit is contained in:
Hugh Rundle 2021-11-01 10:26:17 +11:00
parent 30a959dfce
commit 37148c5127
3 changed files with 19 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load humanize %}
{% load utilities %}
{% block title %}{% if book %}{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}{% else %}{% trans "Add Book" %}{% endif %}{% endblock %}
@ -75,6 +76,9 @@
<p class="help ml-5 mb-2">
<a href="{{ match.local_path }}" target="_blank">{% blocktrans with book_title=match.book_set.first.title %}Author of <em>{{ book_title }}</em>{% endblocktrans %}</a>
</p>
<p class="help ml-5">
{{ author.existing_isnis|get_isni_bio:match }}
</p>
{% endfor %}
<label class="label mt-2">
<input type="radio" name="author_match-{{ counter }}" value="{{ author.name }}" required> {% trans "This is a new author" %}

View file

@ -1,5 +1,6 @@
""" template filters for really common utilities """
import os
from functools import reduce
from uuid import uuid4
from django import template
from django.utils.translation import gettext_lazy as _
@ -66,3 +67,14 @@ def get_book_cover_thumbnail(book, size="medium", ext="jpg"):
return cover_thumbnail.url
except OSError:
return static("images/no_cover.jpg")
@register.filter(name="get_isni_bio")
def get_isni_bio(existing, author):
"""Returns the isni bio string if an existing author has an isni listed"""
if len(existing) == 0:
return ""
match = reduce(
(lambda a: a if a.hasattr("bio") and author.isni == a.isni else ""), existing
)
return match["bio"]

View file

@ -75,11 +75,14 @@ class EditBook(View):
for a in author_matches
if i["isni"] == a.isni
]
isni_matches = list(filter(lambda x: x not in exists, isni_authors))
data["author_matches"].append(
{
"name": author.strip(),
"matches": author_matches,
"existing_isnis": exists,
"isni_matches": isni_matches,
}
)