From d1b5f3b6f0d98fc0076da1f16a5fc465d4877433 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 29 Apr 2021 11:04:14 -0700 Subject: [PATCH] Fixes ranks and normalizes isbns --- bookwyrm/models/book.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index e7c95759a..0539414ad 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -216,7 +216,10 @@ class Edition(Book): # is it in the instance's preferred language? rank += int(bool(DEFAULT_LANGUAGE in self.languages)) # prefer print editions - rank += int(bool(self.physical_format.lower() in ["paperback", "hardcover"])) + if self.physical_format: + rank += int( + bool(self.physical_format.lower() in ["paperback", "hardcover"]) + ) # does it have metadata? rank += int(bool(self.isbn_13)) @@ -236,6 +239,10 @@ class Edition(Book): if self.isbn_10 and not self.isbn_13: self.isbn_13 = isbn_10_to_13(self.isbn_10) + # normalize isbn format + self.isbn_10 = re.sub(r"[^0-9X]", "", self.isbn_10) + self.isbn_13 = re.sub(r"[^0-9X]", "", self.isbn_13) + # set rank self.edition_rank = self.get_rank()