forked from mirrors/bookwyrm
Lookup by openlibrary key
This commit is contained in:
parent
4f1d4d9bc0
commit
bee3c86223
2 changed files with 16 additions and 9 deletions
|
@ -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"""
|
||||
|
|
|
@ -56,14 +56,12 @@ class OpenLibraryImport(TestCase):
|
|||
self.assertEqual(import_items[1].data["Edition Id"], "OL7798182M")
|
||||
|
||||
self.assertEqual(import_items[0].normalized_data["shelf"], "reading")
|
||||
self.assertIsNone(import_items[0].normalized_data["openlibrary_key"])
|
||||
self.assertEqual(import_items[0].normalized_data["openlibrary_key"], "")
|
||||
self.assertEqual(
|
||||
import_items[0].normalized_data["openlibrary_work_key"],
|
||||
"OL102749W"
|
||||
import_items[0].normalized_data["openlibrary_work_key"], "OL102749W"
|
||||
)
|
||||
self.assertEqual(
|
||||
import_items[1].normalized_data["openlibrary_key"],
|
||||
"OL7798182M"
|
||||
import_items[1].normalized_data["openlibrary_key"], "OL7798182M"
|
||||
)
|
||||
self.assertEqual(import_items[2].normalized_data["shelf"], "to-read")
|
||||
self.assertEqual(import_items[3].normalized_data["shelf"], "read")
|
||||
|
|
Loading…
Reference in a new issue