diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index ee1ea270..a96c6096 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 ddac04f3..b4f3e5de 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/tests/views/test_list.py b/bookwyrm/tests/views/test_list.py index cc895ad1..c2c75453 100644 --- a/bookwyrm/tests/views/test_list.py +++ b/bookwyrm/tests/views/test_list.py @@ -271,11 +271,12 @@ class ListViews(TestCase): "", { "book": self.book.id, + "list": self.list.id, }, ) request.user = self.local_user - views.list.add_book(request, self.list.id) + views.list.add_book(request) item = self.list.listitem_set.get() self.assertEqual(item.book, self.book) self.assertEqual(item.user, self.local_user) @@ -300,11 +301,12 @@ class ListViews(TestCase): "", { "book": self.book.id, + "list": self.list.id, }, ) request.user = self.rat - views.list.add_book(request, self.list.id) + views.list.add_book(request) item = self.list.listitem_set.get() self.assertEqual(item.book, self.book) self.assertEqual(item.user, self.rat) @@ -330,11 +332,12 @@ class ListViews(TestCase): "", { "book": self.book.id, + "list": self.list.id, }, ) request.user = self.rat - views.list.add_book(request, self.list.id) + views.list.add_book(request) item = self.list.listitem_set.get() self.assertEqual(item.book, self.book) self.assertEqual(item.user, self.rat) @@ -360,11 +363,12 @@ class ListViews(TestCase): "", { "book": self.book.id, + "list": self.list.id, }, ) request.user = self.local_user - views.list.add_book(request, self.list.id) + views.list.add_book(request) item = self.list.listitem_set.get() self.assertEqual(item.book, self.book) self.assertEqual(item.user, self.local_user) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 3ef2a79b..199827ae 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -117,9 +117,7 @@ urlpatterns = [ # lists 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" - ), + re_path(r"^list/add-book/?$", views.list.add_book, name="list-add-book"), re_path( r"^list/(?P\d+)/remove/?$", views.list.remove_book, diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index ba3200d1..91475d48 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