normalise isbn searching
ISBNs are always numeric except for when the check digit in ISBN-10s is a ten, indicated with a capital X. These changes ensure that ISBNs are always upper-case so that a lower-case 'x' is not used when searching. Additionally some ancient ISBNs have been printed without a leading zero (i.e. they only have 9 characters on the physical book). This change prepends a zero if something looks like an ISBN but only has 9 chars.
This commit is contained in:
parent
c902301d82
commit
da5fd32196
2 changed files with 10 additions and 2 deletions
|
@ -30,7 +30,9 @@ def isbn_search(query):
|
|||
"""search your local database"""
|
||||
if not query:
|
||||
return []
|
||||
|
||||
# Up-case the ISBN string to ensure any 'X' check-digit is correct
|
||||
# If the ISBN has only 9 characters, prepend missing zero
|
||||
query = query.upper().rjust(10, '0')
|
||||
filters = [{f: query} for f in ["isbn_10", "isbn_13"]]
|
||||
results = models.Edition.objects.filter(
|
||||
reduce(operator.or_, (Q(**f) for f in filters))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue