From b17761cfc3062dc152e086a6a5aaeddb719b2e0b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 31 Jan 2021 12:15:38 -0800 Subject: [PATCH] remove items from list --- bookwyrm/templates/lists/list.html | 4 ++-- bookwyrm/urls.py | 2 ++ bookwyrm/views/list.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 76c12aca3..8764d61b4 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -37,9 +37,9 @@

Added by {% include 'snippets/username.html' with user=item.added_by %}

{% if list.user == request.user or list.curation == 'open' and item.added_by == request.user %} - {% endif %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 89cc5c419..ae0f25f38 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -92,6 +92,8 @@ urlpatterns = [ 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/(?P\d+)/remove/?$', + views.list.remove_book, name='list-remove-book'), re_path(r'^list/(?P\d+)/curate/?$', views.Curate.as_view(), name='list-curate'), diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 9e76e12cc..2e9afe336 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -161,3 +161,16 @@ def add_book(request, list_id): return HttpResponseBadRequest() return redirect('list', list_id) + + +@require_POST +def remove_book(request, list_id): + ''' put a book on a list ''' + book_list = get_object_or_404(models.List, id=list_id) + item = get_object_or_404(models.ListItem, id=request.POST.get('item')) + + if not book_list.user == request.user and not item.user == request.user: + return HttpResponseNotFound() + + item.delete() + return redirect('list', list_id)