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 %} {% if author.isni_matches %}
{% for isni_match in author.isni_matches %} {% for isni_match in author.isni_matches %}
<label class="label mt-2"> <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 }} {{ isni_match.name }}
</label> </label>
<p class="help ml-5 mb-2"> <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> </p>
<input type="text" name="isni_match-{{ counter }}" value="{{ isni_match.isni }}" hidden>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% for match in author.matches %} {% 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""" """Returns the isni bio string if an existing author has an isni listed"""
if len(existing) == 0: if len(existing) == 0:
return "" return ""
match = reduce( for value in existing:
(lambda a: a if a.hasattr("bio") and author.isni == a.isni else ""), existing if "bio" in value and author.isni == value["isni"]:
) return value["bio"]
return match["bio"]
return ""

View file

@ -119,3 +119,12 @@ def get_author_isni_data(isni):
author["aliases"].append(make_name_string(entry)) author["aliases"].append(make_name_string(entry))
return author 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 django.views import View
from bookwyrm import book_search, forms, models 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 bookwyrm.views.helpers import get_edition
from .books import set_cover_from_url from .books import set_cover_from_url
@ -168,12 +168,7 @@ class ConfirmEditBook(View):
) )
except ValueError: except ValueError:
# otherwise it's a name with or without isni id # otherwise it's a name with or without isni id
isni = request.POST.get(f"isni_match-{i}") author_data = build_author_dict(match)
author_data = (
get_author_isni_data(isni)
if isni is not None
else {"name": match}
)
author = models.Author.objects.create(**author_data) author = models.Author.objects.create(**author_data)
book.authors.add(author) book.authors.add(author)