Skip to content

Commit

Permalink
Allow users to remove books from suggestion lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Aug 27, 2024
1 parent 2e15c22 commit c901d76
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bookwyrm/templates/lists/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@
</form>
{% endif %}

{% if list.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %}
{% if item.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %}
<form
name="remove-book-{{ item.id }}"
method="post"
action="{% url 'list-remove-book' list.id %}"
action="{{ remove_book_url }}"
class="card-footer-item"
>
{% csrf_token %}
Expand Down
5 changes: 5 additions & 0 deletions bookwyrm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@
views.book_add_suggestion,
name="book-add-suggestion",
),
re_path(
rf"{BOOK_PATH}/suggestions/remove/?$",
views.book_remove_suggestion,
name="book-remove-suggestion",
),
re_path(
r"^author/(?P<author_id>\d+)/update/(?P<connector_identifier>[\w\.]+)/?$",
views.update_author_from_remote,
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

# suggestion lists
from .suggestion_list import SuggestionList
from .suggestion_list import book_add_suggestion
from .suggestion_list import book_add_suggestion, book_remove_suggestion

# misc views
from .author import Author, EditAuthor, update_author_from_remote
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/views/list/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get(self, request, list_id, **kwargs):
"add_failed": add_failed,
"add_succeeded": add_succeeded,
"add_book_url": reverse("list-add-book"),
"remove_book_url": reverse("list-remove-book", args=[list_id]),
}

if request.user.is_authenticated:
Expand Down
18 changes: 16 additions & 2 deletions bookwyrm/views/suggestion_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.settings import PAGE_LENGTH
from bookwyrm.views import Book
from bookwyrm.views.helpers import is_api_request
from bookwyrm.views.helpers import is_api_request, redirect_to_referer
from bookwyrm.views.list.list import get_list_suggestions

# pylint: disable=no-self-use
Expand Down Expand Up @@ -57,6 +57,7 @@ def get(self, request, book_id, **kwargs):
"add_failed": add_failed,
"add_succeeded": add_succeeded,
"add_book_url": reverse("book-add-suggestion", args=[book_id]),
"remove_book_url": reverse("book-remove-suggestion", args=[book_id]),
}

if request.user.is_authenticated:
Expand Down Expand Up @@ -97,4 +98,17 @@ def book_add_suggestion(request, book_id):
item = form.save(request, commit=False)
item.save()

return Book().get(request, book_id, add_succeeded=True)
return redirect_to_referer(request)


@require_POST
@login_required
def book_remove_suggestion(request, _):
"""remove a book from a suggestion list"""
item = get_object_or_404(models.SuggestionListItem, id=request.POST.get("item"))
item.raise_not_deletable(request.user)

with transaction.atomic():
item.delete()

return redirect_to_referer(request)

0 comments on commit c901d76

Please sign in to comment.