From 0c9b3c4d5f6df4495b79e4265b06d9231d9397e1 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 20 Feb 2020 13:42:22 +0100 Subject: [PATCH] =?UTF-8?q?Le=20Fetch=20ouvre=20ensuite=20la=20page=20pour?= =?UTF-8?q?=20entrer=20un=20nouveau=20m=C3=A9dia=20(code=20sans=20doute=20?= =?UTF-8?q?temporaire)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media/forms.py | 7 ++++--- media/templates/media/isbn_button.html | 3 ++- tool_barcode_getblue.py | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/media/forms.py b/media/forms.py index b3c3775..f904bf4 100644 --- a/media/forms.py +++ b/media/forms.py @@ -26,6 +26,8 @@ class MediaAdminForm(ModelForm): Download data from bedeteque :return True if success """ + print(self.request.POST) + print('isbn' in self.request.POST) scraper = BedetequeScraper() r = scraper.search_by_isbn(isbn) if not r: @@ -33,7 +35,6 @@ class MediaAdminForm(ModelForm): # If results, then take the most accurate data = scraper.scrap_bd_info(r[0]) self.cleaned_data.update(data) - print(self.cleaned_data) return True def download_data_openlibrary(self, isbn): @@ -93,7 +94,7 @@ class MediaAdminForm(ModelForm): """ super().clean() - if "_continue" in self.request.POST: + if "_isbn" in self.request.POST: isbn = self.cleaned_data.get('isbn') if isbn: # ISBN is present, try with bedeteque @@ -175,7 +176,7 @@ class MediaAdminForm(ModelForm): from django.core.exceptions import ValidationError try: # We don't want to check a field when we enter an ISBN. - if "_continue" not in self.request.POST \ + if "isbn" not in self.request.POST \ or not self.cleaned_data.get('isbn'): value = field.clean(value) self.cleaned_data[name] = value diff --git a/media/templates/media/isbn_button.html b/media/templates/media/isbn_button.html index 36bd9b2..1d1903d 100644 --- a/media/templates/media/isbn_button.html +++ b/media/templates/media/isbn_button.html @@ -1,3 +1,4 @@ {% load i18n %} {% include "django/forms/widgets/input.html" %} - \ No newline at end of file + + \ No newline at end of file diff --git a/tool_barcode_getblue.py b/tool_barcode_getblue.py index fd5b8cf..533414a 100644 --- a/tool_barcode_getblue.py +++ b/tool_barcode_getblue.py @@ -22,6 +22,9 @@ class Server(BaseHTTPRequestHandler): def do_GET(self): self._set_headers() isbn = self.path[7:-24] + if not isbn.isnumeric(): + print("Mauvais ISBN.") + return print("Hey j'ai un ISBN :", isbn) os.system("xdotool type " + isbn) os.system("xdotool key KP_Enter")