From 0941c50c6913d94430d03525396df1b9dca75d3d Mon Sep 17 00:00:00 2001 From: n2no1 <7995366-n2no1@users.noreply.gitlab.com> Date: Tue, 6 Apr 2021 20:43:37 -0400 Subject: [PATCH] ensure that the book edit confirmation receives initial date data as a datetime --- bookwyrm/templates/book/edit_book.html | 4 ++-- bookwyrm/views/books.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/book/edit_book.html b/bookwyrm/templates/book/edit_book.html index 8cf6f31c..0cde8dff 100644 --- a/bookwyrm/templates/book/edit_book.html +++ b/bookwyrm/templates/book/edit_book.html @@ -124,7 +124,7 @@

- +

{% for error in form.first_published_date.errors %}

{{ error | escape }}

@@ -132,7 +132,7 @@

- +

{% for error in form.published_date.errors %}

{{ error | escape }}

diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 58886cad..e982a7d3 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -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")