Le Fetch ouvre ensuite la page pour entrer un nouveau média (code sans doute temporaire)

This commit is contained in:
Yohann D'ANELLO 2020-02-20 13:42:22 +01:00
parent 39c3a59838
commit 0c9b3c4d5f
3 changed files with 9 additions and 4 deletions

View File

@ -26,6 +26,8 @@ class MediaAdminForm(ModelForm):
Download data from bedeteque Download data from bedeteque
:return True if success :return True if success
""" """
print(self.request.POST)
print('isbn' in self.request.POST)
scraper = BedetequeScraper() scraper = BedetequeScraper()
r = scraper.search_by_isbn(isbn) r = scraper.search_by_isbn(isbn)
if not r: if not r:
@ -33,7 +35,6 @@ class MediaAdminForm(ModelForm):
# If results, then take the most accurate # If results, then take the most accurate
data = scraper.scrap_bd_info(r[0]) data = scraper.scrap_bd_info(r[0])
self.cleaned_data.update(data) self.cleaned_data.update(data)
print(self.cleaned_data)
return True return True
def download_data_openlibrary(self, isbn): def download_data_openlibrary(self, isbn):
@ -93,7 +94,7 @@ class MediaAdminForm(ModelForm):
""" """
super().clean() super().clean()
if "_continue" in self.request.POST: if "_isbn" in self.request.POST:
isbn = self.cleaned_data.get('isbn') isbn = self.cleaned_data.get('isbn')
if isbn: if isbn:
# ISBN is present, try with bedeteque # ISBN is present, try with bedeteque
@ -175,7 +176,7 @@ class MediaAdminForm(ModelForm):
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
try: try:
# We don't want to check a field when we enter an ISBN. # 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'): or not self.cleaned_data.get('isbn'):
value = field.clean(value) value = field.clean(value)
self.cleaned_data[name] = value self.cleaned_data[name] = value

View File

@ -1,3 +1,4 @@
{% load i18n %} {% load i18n %}
{% include "django/forms/widgets/input.html" %} {% include "django/forms/widgets/input.html" %}
<input type="submit" value="{% trans "Fetch data" %}" name="_continue"> <input type="submit" value="{% trans "Fetch data" %}" name="_isbn">
<input type="hidden" name="_addanother" value="42">

View File

@ -22,6 +22,9 @@ class Server(BaseHTTPRequestHandler):
def do_GET(self): def do_GET(self):
self._set_headers() self._set_headers()
isbn = self.path[7:-24] isbn = self.path[7:-24]
if not isbn.isnumeric():
print("Mauvais ISBN.")
return
print("Hey j'ai un ISBN :", isbn) print("Hey j'ai un ISBN :", isbn)
os.system("xdotool type " + isbn) os.system("xdotool type " + isbn)
os.system("xdotool key KP_Enter") os.system("xdotool key KP_Enter")