mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-06-07 08:18:50 +00:00
Allow users to remove books from suggestion lists
This commit is contained in:
parent
2e15c227f3
commit
c901d76705
5 changed files with 25 additions and 5 deletions
|
@ -113,11 +113,11 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% 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
|
<form
|
||||||
name="remove-book-{{ item.id }}"
|
name="remove-book-{{ item.id }}"
|
||||||
method="post"
|
method="post"
|
||||||
action="{% url 'list-remove-book' list.id %}"
|
action="{{ remove_book_url }}"
|
||||||
class="card-footer-item"
|
class="card-footer-item"
|
||||||
>
|
>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -770,6 +770,11 @@ urlpatterns = [
|
||||||
views.book_add_suggestion,
|
views.book_add_suggestion,
|
||||||
name="book-add-suggestion",
|
name="book-add-suggestion",
|
||||||
),
|
),
|
||||||
|
re_path(
|
||||||
|
rf"{BOOK_PATH}/suggestions/remove/?$",
|
||||||
|
views.book_remove_suggestion,
|
||||||
|
name="book-remove-suggestion",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^author/(?P<author_id>\d+)/update/(?P<connector_identifier>[\w\.]+)/?$",
|
r"^author/(?P<author_id>\d+)/update/(?P<connector_identifier>[\w\.]+)/?$",
|
||||||
views.update_author_from_remote,
|
views.update_author_from_remote,
|
||||||
|
|
|
@ -107,7 +107,7 @@ from .list.list import (
|
||||||
|
|
||||||
# suggestion lists
|
# suggestion lists
|
||||||
from .suggestion_list import SuggestionList
|
from .suggestion_list import SuggestionList
|
||||||
from .suggestion_list import book_add_suggestion
|
from .suggestion_list import book_add_suggestion, book_remove_suggestion
|
||||||
|
|
||||||
# misc views
|
# misc views
|
||||||
from .author import Author, EditAuthor, update_author_from_remote
|
from .author import Author, EditAuthor, update_author_from_remote
|
||||||
|
|
|
@ -74,6 +74,7 @@ class List(View):
|
||||||
"add_failed": add_failed,
|
"add_failed": add_failed,
|
||||||
"add_succeeded": add_succeeded,
|
"add_succeeded": add_succeeded,
|
||||||
"add_book_url": reverse("list-add-book"),
|
"add_book_url": reverse("list-add-book"),
|
||||||
|
"remove_book_url": reverse("list-remove-book", args=[list_id]),
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
|
|
@ -13,7 +13,7 @@ from bookwyrm import forms, models
|
||||||
from bookwyrm.activitypub import ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
from bookwyrm.views import Book
|
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
|
from bookwyrm.views.list.list import get_list_suggestions
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
|
@ -57,6 +57,7 @@ class SuggestionList(View):
|
||||||
"add_failed": add_failed,
|
"add_failed": add_failed,
|
||||||
"add_succeeded": add_succeeded,
|
"add_succeeded": add_succeeded,
|
||||||
"add_book_url": reverse("book-add-suggestion", args=[book_id]),
|
"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:
|
if request.user.is_authenticated:
|
||||||
|
@ -97,4 +98,17 @@ def book_add_suggestion(request, book_id):
|
||||||
item = form.save(request, commit=False)
|
item = form.save(request, commit=False)
|
||||||
item.save()
|
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)
|
||||||
|
|
Loading…
Reference in a new issue