mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 19:10:35 +00:00
Merge pull request #745 from mouse-reeve/list-add
Add books to lists from the book page
This commit is contained in:
commit
e6e1af9ec1
5 changed files with 35 additions and 12 deletions
|
@ -233,7 +233,7 @@
|
|||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if lists.exists %}
|
||||
{% if lists.exists or request.user.list_set.exists %}
|
||||
<section class="content block">
|
||||
<h2 class="title is-5">{% trans "Lists" %}</h2>
|
||||
<ul>
|
||||
|
@ -241,6 +241,26 @@
|
|||
<li><a href="{{ list.local_path }}">{{ list.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if request.user.list_set.exists %}
|
||||
<form name="list-add" method="post" action="{% url 'list-add-book' %}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ book.id }}">
|
||||
<label class="label" for="id_list">{% trans "Add to list" %}</label>
|
||||
<div class="field has-addons">
|
||||
<div class="select control">
|
||||
<select name="list" id="id_list">
|
||||
{% for list in user.list_set.all %}
|
||||
<option value="{{ list.id }}">{{ list.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-link">{% trans "Add" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -83,9 +83,10 @@
|
|||
</div>
|
||||
<div class="column">
|
||||
<p>{% include 'snippets/book_titleby.html' with book=book %}</p>
|
||||
<form name="add-book" method="post" action="{% url 'list-add-book' list.id %}">
|
||||
<form name="add-book" method="post" action="{% url 'list-add-book' %}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ book.id }}">
|
||||
<input type="hidden" name="list" value="{{ list.id }}">
|
||||
<button type="submit" class="button is-small is-link">{% if list.curation == 'open' or request.user == list.user %}{% trans "Add" %}{% else %}{% trans "Suggest" %}{% endif %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -117,9 +117,7 @@ urlpatterns = [
|
|||
# lists
|
||||
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
|
||||
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
|
||||
re_path(
|
||||
r"^list/(?P<list_id>\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<list_id>\d+)/remove/?$",
|
||||
views.list.remove_book,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue