This commit is contained in:
Pablo Barton 2021-04-17 22:09:00 -04:00
parent 9031184176
commit 602c8c83ba
2 changed files with 12 additions and 14 deletions

View file

@ -361,7 +361,8 @@ class ListViews(TestCase):
remove_request = self.factory.post("", {"item": items[1].id})
remove_request.user = self.local_user
views.list.remove_book(remove_request, self.list.id)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.list.remove_book(remove_request, self.list.id)
items = self.list.listitem_set.order_by("order").all()
self.assertEqual(items[0].book, self.book)
self.assertEqual(items[1].book, self.book_three)
@ -415,7 +416,8 @@ class ListViews(TestCase):
set_position_request = self.factory.post("", {"position": 1})
set_position_request.user = self.local_user
views.list.set_book_position(set_position_request, items[2].id)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.list.set_book_position(set_position_request, items[2].id)
items = self.list.listitem_set.order_by("order").all()
self.assertEqual(items[0].book, self.book_three)
self.assertEqual(items[1].book, self.book)

View file

@ -124,27 +124,23 @@ class List(View):
directional_sort_by = "-" + directional_sort_by
if sort_by == "order":
items = (
book_list.listitem_set
.filter(approved=True)
.order_by(directional_sort_by)
items = book_list.listitem_set.filter(approved=True).order_by(
directional_sort_by
)
elif sort_by == "title":
items = (
book_list.listitem_set
.filter(approved=True)
.order_by(
directional_sort_by)
items = book_list.listitem_set.filter(approved=True).order_by(
directional_sort_by
)
elif sort_by == "rating":
items = (
book_list.listitem_set
.annotate(average_rating=Avg(Coalesce("book__review__rating", 0)))
book_list.listitem_set.annotate(
average_rating=Avg(Coalesce("book__review__rating", 0))
)
.filter(approved=True)
.order_by(directional_sort_by)
)
paginated = Paginator(items, 2)
paginated = Paginator(items, 25)
if query and request.user.is_authenticated:
# search for books