select correct isni record when adding authors

The original implementation of this was so, so broken.
Now it's not.
This commit is contained in:
Hugh Rundle 2021-11-01 11:34:32 +11:00
parent 37148c5127
commit 552980e208
4 changed files with 18 additions and 14 deletions

View file

@ -59,13 +59,12 @@
{% if author.isni_matches %}
{% for isni_match in author.isni_matches %}
<label class="label mt-2">
<input type="radio" name="author_match-{{ counter }}" value="{{ isni_match.name }}" required>
<input type="radio" name="author_match-{{ counter }}" value="isni_match_{{ isni_match.isni }}" required>
{{ isni_match.name }}
</label>
<p class="help ml-5 mb-2">
<a href="{{ match.uri }}" target="_blank">{{ isni_match.bio }}</a>
<a href="{{ isni_match.uri }}" target="_blank">{{ isni_match.bio }}</a>
</p>
<input type="text" name="isni_match-{{ counter }}" value="{{ isni_match.isni }}" hidden>
{% endfor %}
{% endif %}
{% for match in author.matches %}

View file

@ -74,7 +74,8 @@ 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"]
for value in existing:
if "bio" in value and author.isni == value["isni"]:
return value["bio"]
return ""

View file

@ -119,3 +119,12 @@ def get_author_isni_data(isni):
author["aliases"].append(make_name_string(entry))
return author
def build_author_dict(match_value):
# if it is an isni value get the data
if match_value.startswith("isni_match_"):
isni = match_value.replace("isni_match_", "")
return get_author_isni_data(isni)
# otherwise it's a name string
return {"name": match_value}

View file

@ -11,7 +11,7 @@ from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import book_search, forms, models
from bookwyrm.utils.isni import find_authors_by_name, get_author_isni_data
from bookwyrm.utils.isni import find_authors_by_name, build_author_dict
from bookwyrm.views.helpers import get_edition
from .books import set_cover_from_url
@ -168,12 +168,7 @@ class ConfirmEditBook(View):
)
except ValueError:
# otherwise it's a name with or without isni id
isni = request.POST.get(f"isni_match-{i}")
author_data = (
get_author_isni_data(isni)
if isni is not None
else {"name": match}
)
author_data = build_author_dict(match)
author = models.Author.objects.create(**author_data)
book.authors.add(author)