From 4cf3f378ef6bd79278f3b2d5305a9fc7e7b19485 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 12 Jan 2022 10:07:49 -0800 Subject: [PATCH] Delete view --- bookwyrm/templates/book/edit_links.html | 15 ++++++++++++++- bookwyrm/templates/book/links.html | 14 ++++++++------ bookwyrm/urls.py | 15 +++++++++++++-- bookwyrm/views/books/links.py | 6 ++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/bookwyrm/templates/book/edit_links.html b/bookwyrm/templates/book/edit_links.html index b145ce156..c56f97a62 100644 --- a/bookwyrm/templates/book/edit_links.html +++ b/bookwyrm/templates/book/edit_links.html @@ -53,7 +53,10 @@

- +
+ {% csrf_token %} + +
{% endfor %} @@ -64,6 +67,16 @@ {% endif %} + + {% url 'file-link-add' book.id as fallback_url %} +
+ +
{% endblock %} diff --git a/bookwyrm/templates/book/links.html b/bookwyrm/templates/book/links.html index ef2c0a402..c77e21464 100644 --- a/bookwyrm/templates/book/links.html +++ b/bookwyrm/templates/book/links.html @@ -11,13 +11,15 @@ {% if can_edit_book %}
{% url 'file-link-add' book.id as fallback_url %} - + +
{% endif %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index ace7f2d02..990601490 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -469,8 +469,19 @@ urlpatterns = [ views.add_description, name="add-description", ), - re_path(rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"), - re_path(rf"{BOOK_PATH}/filelink/add/?$", views.AddFileLink.as_view(), name="file-link-add"), + re_path( + rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link" + ), + re_path( + rf"{BOOK_PATH}/filelink/(?P\d+)/delete/?$", + views.BookFileLinks.as_view(), + name="file-link", + ), + re_path( + rf"{BOOK_PATH}/filelink/add/?$", + views.AddFileLink.as_view(), + name="file-link-add", + ), re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"), re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"), re_path( diff --git a/bookwyrm/views/books/links.py b/bookwyrm/views/books/links.py index da4fa5edf..e10e87512 100644 --- a/bookwyrm/views/books/links.py +++ b/bookwyrm/views/books/links.py @@ -18,6 +18,12 @@ class BookFileLinks(View): book = get_object_or_404(models.Edition, id=book_id) return TemplateResponse(request, "book/edit_links.html", {"book": book}) + def post(self, request, book_id, link_id): + """delete link""" + link = get_object_or_404(models.FileLink, id=link_id, book=book_id) + link.delete() + return self.get(request, book_id) + @method_decorator(login_required, name="dispatch") @method_decorator(