mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-09-22 03:20:03 +00:00
strip leading and following spaces from ISBN
This commit is contained in:
parent
da5fd32196
commit
f219851f3a
2 changed files with 3 additions and 4 deletions
|
@ -32,7 +32,7 @@ def isbn_search(query):
|
||||||
return []
|
return []
|
||||||
# Up-case the ISBN string to ensure any 'X' check-digit is correct
|
# Up-case the ISBN string to ensure any 'X' check-digit is correct
|
||||||
# If the ISBN has only 9 characters, prepend missing zero
|
# If the ISBN has only 9 characters, prepend missing zero
|
||||||
query = query.upper().rjust(10, '0')
|
query = query.strip().upper().rjust(10, '0')
|
||||||
filters = [{f: query} for f in ["isbn_10", "isbn_13"]]
|
filters = [{f: query} for f in ["isbn_10", "isbn_13"]]
|
||||||
results = models.Edition.objects.filter(
|
results = models.Edition.objects.filter(
|
||||||
reduce(operator.or_, (Q(**f) for f in filters))
|
reduce(operator.or_, (Q(**f) for f in filters))
|
||||||
|
|
|
@ -44,9 +44,8 @@ class AbstractMinimalConnector(ABC):
|
||||||
if maybe_isbn(query) and self.isbn_search_url and self.isbn_search_url != "":
|
if maybe_isbn(query) and self.isbn_search_url and self.isbn_search_url != "":
|
||||||
# Up-case the ISBN string to ensure any 'X' check-digit is correct
|
# Up-case the ISBN string to ensure any 'X' check-digit is correct
|
||||||
# If the ISBN has only 9 characters, prepend missing zero
|
# If the ISBN has only 9 characters, prepend missing zero
|
||||||
query = query.upper().rjust(10, '0')
|
normalized_query = query.strip().upper().rjust(10, '0')
|
||||||
return f"{self.isbn_search_url}{query}"
|
return f"{self.isbn_search_url}{normalized_query}"
|
||||||
|
|
||||||
# NOTE: previously, we tried searching isbn and if that produces no results,
|
# NOTE: previously, we tried searching isbn and if that produces no results,
|
||||||
# searched as free text. This, instead, only searches isbn if it's isbn-y
|
# searched as free text. This, instead, only searches isbn if it's isbn-y
|
||||||
return f"{self.search_url}{query}"
|
return f"{self.search_url}{query}"
|
||||||
|
|
Loading…
Reference in a new issue