diff --git a/media/forms.py b/media/forms.py index ee95296..5dfc41b 100644 --- a/media/forms.py +++ b/media/forms.py @@ -96,8 +96,13 @@ class MediaAdminForm(ModelForm): req = urllib.request.Request(api_url) req.add_header("Authorization", os.getenv("ISBNDB_KEY")) with urllib.request.urlopen(req) as url: - data = json.loads(url.read().decode()) + data: dict = json.loads(url.read().decode())["book"] print(data) + data.setdefault("title", "") + data.setdefault("date_published", "1970-01-01") + data.setdefault("pages", 0) + data.setdefault("authors", []) + data.setdefault("image", "") self.cleaned_data["title"] = data["title"] self.cleaned_data["published_date"] = data["date_published"][:10] self.cleaned_data["number_of_pages"] = data["pages"] diff --git a/media/management/commands/import_future_media.py b/media/management/commands/import_future_media.py index d9af5de..9ec6a49 100644 --- a/media/management/commands/import_future_media.py +++ b/media/management/commands/import_future_media.py @@ -46,4 +46,4 @@ class Command(BaseCommand): except Exception as e: self.stderr.write(self.style.WARNING( "An error occured while importing ISBN {isbn}: {error}" - .format(isbn=isbn, error=str(e)))) + .format(isbn=isbn, error=str(e.__class__) + "(" + str(e) + ")")))