mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-10-31 22:19:00 +00:00
Fixes #2571
Persist book.subjects and add_author when form validation fails. This does not resolve the problem of cover image uploads being dropped because this is a broader problem and is covered separately in #2760 (we should investigate the plugin ` django-file-resubmit`)
This commit is contained in:
parent
7272ca2564
commit
fb3cb229e9
1 changed files with 8 additions and 3 deletions
|
@ -102,11 +102,13 @@ class CreateBook(View):
|
|||
"authors": authors,
|
||||
}
|
||||
|
||||
ensure_transient_values_persist(request, data)
|
||||
|
||||
if not form.is_valid():
|
||||
ensure_transient_values_persist(request, data, 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)
|
||||
data = add_authors(request, data)
|
||||
|
||||
# check if this is an edition of an existing work
|
||||
|
@ -139,8 +141,11 @@ class CreateBook(View):
|
|||
return redirect(f"/book/{book.id}")
|
||||
|
||||
|
||||
def ensure_transient_values_persist(request, data):
|
||||
def ensure_transient_values_persist(request, data, form):
|
||||
"""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["add_author"] = request.POST.getlist("add_author")
|
||||
data["cover_url"] = request.POST.get("cover-url")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue