fix ensure_transient_values_persist call

This commit is contained in:
Hugh Rundle 2023-04-16 19:06:04 +10:00
parent 74f08323d1
commit 6f025af99f

View file

@ -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")