From f0a936f15ebfd5d73527ac3105341d35f2e82074 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 15 Mar 2021 14:44:03 -0700 Subject: [PATCH] Add books to lists from the book page --- bookwyrm/templates/book.html | 22 +++++++++++++++++++++- bookwyrm/templates/lists/list.html | 3 ++- bookwyrm/urls.py | 2 +- bookwyrm/views/list.py | 6 +++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index ee1ea270b..a96c60962 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -233,7 +233,7 @@ {% endif %} - {% if lists.exists %} + {% if lists.exists or request.user.list_set.exists %}

{% trans "Lists" %}

+ + {% if request.user.list_set.exists %} +
+ {% csrf_token %} + + +
+
+ +
+
+ +
+
+
+ {% endif %}
{% endif %} diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index ddac04f3b..b4f3e5dee 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -83,9 +83,10 @@

{% include 'snippets/book_titleby.html' with book=book %}

-
+ {% csrf_token %} +
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 3ef2a79b8..05382e93f 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -118,7 +118,7 @@ urlpatterns = [ re_path(r"^list/?$", views.Lists.as_view(), name="lists"), re_path(r"^list/(?P\d+)(.json)?/?$", views.List.as_view(), name="list"), re_path( - r"^list/(?P\d+)/add/?$", views.list.add_book, name="list-add-book" + r"^list/add-book/?$", views.list.add_book, name="list-add-book" ), re_path( r"^list/(?P\d+)/remove/?$", diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index ba3200d1e..eb82a0f15 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -173,9 +173,9 @@ class Curate(View): @require_POST -def add_book(request, list_id): +def add_book(request): """ put a book on a list """ - book_list = get_object_or_404(models.List, id=list_id) + book_list = get_object_or_404(models.List, id=request.POST.get('list')) if not object_visible_to_user(request.user, book_list): return HttpResponseNotFound() @@ -204,7 +204,7 @@ def add_book(request, list_id): # if the book is already on the list, don't flip out pass - return redirect("list", list_id) + return redirect("list", book_list.id) @require_POST