Lookup by openlibrary key

This commit is contained in:
Mouse Reeve
2021-12-14 12:49:00 -08:00
parent 4f1d4d9bc0
commit bee3c86223
2 changed files with 16 additions and 9 deletions

View File

@ -88,7 +88,9 @@ class ImportItem(models.Model):
return
if self.isbn:
self.book = self.get_book_from_isbn()
self.book = self.get_book_from_identifier()
elif self.openlibrary_key:
self.book = self.get_book_from_identifier(field="openlibrary_key")
else:
# don't fall back on title/author search if isbn is present.
# you're too likely to mismatch
@ -98,10 +100,10 @@ class ImportItem(models.Model):
else:
self.book_guess = book
def get_book_from_isbn(self):
"""search by isbn"""
def get_book_from_identifier(self, field="isbn"):
"""search by isbn or other unique identifier"""
search_result = connector_manager.first_search_result(
self.isbn, min_confidence=0.999
getattr(self, field), min_confidence=0.999
)
if search_result:
# it's already in the right format
@ -147,6 +149,13 @@ class ImportItem(models.Model):
self.normalized_data.get("isbn_10")
)
@property
def openlibrary_key(self):
"""the edition identifier is preferable to the work key"""
return self.normalized_data.get("openlibrary_key") or self.normalized_data.get(
"openlibrary_work_key"
)
@property
def shelf(self):
"""the goodreads shelf field"""