diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py index 829b7a6c0..d5b3e2573 100644 --- a/bookwyrm/views/books/edit_book.py +++ b/bookwyrm/views/books/edit_book.py @@ -103,12 +103,12 @@ class CreateBook(View): } if not form.is_valid(): - ensure_transient_values_persist(request, data, form) + ensure_transient_values_persist(request, data, form=form) return TemplateResponse(request, "book/edit/edit_book.html", data) # we have to call this twice because it requires form.cleaned_data # which only exists after we validate the form - ensure_transient_values_persist(request, data, form) + ensure_transient_values_persist(request, data, form=form) data = add_authors(request, data) # check if this is an edition of an existing work @@ -141,10 +141,10 @@ class CreateBook(View): return redirect(f"/book/{book.id}") -def ensure_transient_values_persist(request, data, form): +def ensure_transient_values_persist(request, data, **kwargs): """ensure that values of transient form fields persist when re-rendering the form""" data["book"] = data.get("book") or {} - data["book"]["subjects"] = form.cleaned_data["subjects"] + data["book"]["subjects"] = kwargs["form"].cleaned_data["subjects"] data["add_author"] = request.POST.getlist("add_author") data["cover_url"] = request.POST.get("cover-url")