From 665f7a287542a278a27fa0931d490b981198d236 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 3 Oct 2020 15:10:43 +0200 Subject: [PATCH] Ensure that the fetched roman ISBN is the queried ISBN --- media/forms.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/media/forms.py b/media/forms.py index 9a894af..00cc1b9 100644 --- a/media/forms.py +++ b/media/forms.py @@ -115,9 +115,18 @@ class MediaAdminForm(ModelForm): data = json.loads(url.read().decode()) if data and data['totalItems']: - data = data['items'][0] + fetched_item = None + for item in data['items']: + for identifiers in item["volumeInfo"]["industryIdentifiers"]: + if identifiers["identifier"] == isbn: + fetched_item = item + break + if fetched_item: + break + if not fetched_item: + return False # Fill the data - self.parse_data_google(data) + self.parse_data_google(fetched_item) return True return False