From c8e038cd4e7fa3dffcce4a4f7011de86f4a69c42 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 15 Dec 2021 13:20:05 -0800 Subject: [PATCH] Adds form errors --- bookwyrm/templates/book/file_link_modal.html | 5 ++++- bookwyrm/views/books/links.py | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/book/file_link_modal.html b/bookwyrm/templates/book/file_link_modal.html index 3870eb8e6..5ffe8ce80 100644 --- a/bookwyrm/templates/book/file_link_modal.html +++ b/bookwyrm/templates/book/file_link_modal.html @@ -14,16 +14,19 @@
{{ file_link_form.name }} + {% include 'snippets/form_errors.html' with errors_list=file_link_form.name.errors id="desc_name" %}
- + + {% include 'snippets/form_errors.html' with errors_list=file_link_form.url.errors id="desc_url" %}
+ {% include 'snippets/form_errors.html' with errors_list=file_link_form.filetype.errors id="desc_filetype" %}
diff --git a/bookwyrm/views/books/links.py b/bookwyrm/views/books/links.py index 722d0545a..949c807f5 100644 --- a/bookwyrm/views/books/links.py +++ b/bookwyrm/views/books/links.py @@ -28,10 +28,11 @@ class FileLink(View): return TemplateResponse(request, "book/file_link_page.html", data) @transaction.atomic - def post(self, request, book_id): + def post(self, request, book_id, link_id=None): """Add a link to a copy of the book you can read""" book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id) - form = forms.FileLinkForm(request.POST) + link = get_object_or_404(models.FileLink, id=link_id) if link_id else None + form = forms.FileLinkForm(request.POST, instance=link) if not form.is_valid(): data = {"file_link_form": form, "book": book} return TemplateResponse(request, "book/file_link_page.html", data)