From 51e16fba97b459eb110294628653db298aa8489c Mon Sep 17 00:00:00 2001 From: n2no1 <7995366-n2no1@users.noreply.gitlab.com> Date: Tue, 6 Apr 2021 20:49:19 -0400 Subject: [PATCH] run black, add a try/catch around the formcopy fix --- bookwyrm/views/books.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index e982a7d3..02f61ea7 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -176,8 +176,18 @@ class EditBook(View): # we have to make sure the dates are passed in as datetime, they're currently a string # QueryDicts are immutable, we need to copy formcopy = data["form"].data.copy() - formcopy["first_published_date"] = datetime.strptime(formcopy["first_published_date"], "%Y-%m-%d") - formcopy["published_date"] = datetime.strptime(formcopy["published_date"], "%Y-%m-%d") + try: + formcopy["first_published_date"] = datetime.strptime( + formcopy["first_published_date"], "%Y-%m-%d" + ) + except MultiValueDictKeyError: + pass + try: + formcopy["published_date"] = datetime.strptime( + formcopy["published_date"], "%Y-%m-%d" + ) + except MultiValueDictKeyError: + pass data["form"].data = formcopy return TemplateResponse(request, "book/edit_book.html", data)