ensure that the book edit confirmation receives initial date data as a datetime

This commit is contained in:
n2no1
2021-04-06 20:43:37 -04:00
parent 502f29082c
commit 0941c50c69
2 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,5 @@
""" the good stuff! the books! """
from datetime import datetime
from uuid import uuid4
from django.contrib.auth.decorators import login_required, permission_required
@ -172,6 +173,12 @@ class EditBook(View):
data["confirm_mode"] = True
# this isn't preserved because it isn't part of the form obj
data["remove_authors"] = request.POST.getlist("remove_authors")
# 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")
data["form"].data = formcopy
return TemplateResponse(request, "book/edit_book.html", data)
remove_authors = request.POST.getlist("remove_authors")