forked from mirrors/bookwyrm
Merge pull request #913 from mouse-reeve/edit-book-date-error
Fixes edit book form throwing error on empty dates
This commit is contained in:
commit
e339581ade
2 changed files with 4 additions and 5 deletions
|
@ -98,7 +98,7 @@
|
||||||
|
|
||||||
<p class="mb-2">
|
<p class="mb-2">
|
||||||
<label class="label" for="id_subtitle">{% trans "Subtitle:" %}</label>
|
<label class="label" for="id_subtitle">{% trans "Subtitle:" %}</label>
|
||||||
<input type="text" name="subtitle" value="{{ form.subtitle.value|default:'' }}" maxlength="255" class="input" required="" id="id_subtitle">
|
<input type="text" name="subtitle" value="{{ form.subtitle.value|default:'' }}" maxlength="255" class="input" id="id_subtitle">
|
||||||
</p>
|
</p>
|
||||||
{% for error in form.subtitle.errors %}
|
{% for error in form.subtitle.errors %}
|
||||||
<p class="help is-danger">{{ error | escape }}</p>
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
""" the good stuff! the books! """
|
""" the good stuff! the books! """
|
||||||
from datetime import datetime
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from dateutil.parser import parse as dateparse
|
from dateutil.parser import parse as dateparse
|
||||||
|
@ -175,18 +174,18 @@ class EditBook(View):
|
||||||
data["confirm_mode"] = True
|
data["confirm_mode"] = True
|
||||||
# this isn't preserved because it isn't part of the form obj
|
# this isn't preserved because it isn't part of the form obj
|
||||||
data["remove_authors"] = request.POST.getlist("remove_authors")
|
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
|
# make sure the dates are passed in as datetime, they're currently a string
|
||||||
# QueryDicts are immutable, we need to copy
|
# QueryDicts are immutable, we need to copy
|
||||||
formcopy = data["form"].data.copy()
|
formcopy = data["form"].data.copy()
|
||||||
try:
|
try:
|
||||||
formcopy["first_published_date"] = dateparse(
|
formcopy["first_published_date"] = dateparse(
|
||||||
formcopy["first_published_date"]
|
formcopy["first_published_date"]
|
||||||
)
|
)
|
||||||
except MultiValueDictKeyError:
|
except (MultiValueDictKeyError, ValueError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
formcopy["published_date"] = dateparse(formcopy["published_date"])
|
formcopy["published_date"] = dateparse(formcopy["published_date"])
|
||||||
except MultiValueDictKeyError:
|
except (MultiValueDictKeyError, ValueError):
|
||||||
pass
|
pass
|
||||||
data["form"].data = formcopy
|
data["form"].data = formcopy
|
||||||
return TemplateResponse(request, "book/edit_book.html", data)
|
return TemplateResponse(request, "book/edit_book.html", data)
|
||||||
|
|
Loading…
Reference in a new issue