Show error message when start and finish date is invalid

This commit is contained in:
Mouse Reeve
2022-01-11 10:22:01 -08:00
parent 9521c477b2
commit cdaf0fe8e3
4 changed files with 78 additions and 8 deletions

View File

@ -124,9 +124,8 @@ class CreateReadThrough(View):
def post(self, request):
"""can't use the form normally because the dates are too finnicky"""
print("hi")
book_id = request.POST.get("book")
normalized_post = request.POST.copy()
print(normalized_post)
normalized_post["start_date"] = load_date_in_user_tz_as_utc(
request.POST.get("start_date"), request.user
@ -134,13 +133,15 @@ class CreateReadThrough(View):
normalized_post["finish_date"] = load_date_in_user_tz_as_utc(
request.POST.get("finish_date"), request.user
)
form = forms.ReadThroughForm(normalized_post)
form = forms.ReadThroughForm(request.POST)
if not form.is_valid():
print(form.errors)
# TODO error handling
return ""
book = get_object_or_404(models.Edition, id=book_id)
data = {"form": form, "book": book}
return TemplateResponse(
request, "readthrough/readthrough.html", data
)
form.save()
return redirect("book", request.POST.get("book"))
return redirect("book", book_id)