From 28a8edfdc460dba2692790195f1eef44498cfb8f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 19:06:47 -0800 Subject: [PATCH 1/4] Fixes author page query --- bookwyrm/views/author.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 3310fef0..b50653f9 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -1,6 +1,7 @@ """ the good people stuff! the authors! """ from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator +from django.db.models import Q from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator @@ -26,7 +27,7 @@ class Author(View): return ActivitypubResponse(author.to_activity()) books = models.Work.objects.filter( - authors=author, editions__authors=author + Q(authors=author) | Q(editions__authors=author) ).distinct() paginated = Paginator(books, PAGE_LENGTH) From a9a6fd12429d41ec1b2f0ebeaa57ab080ab61793 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 19:34:37 -0800 Subject: [PATCH 2/4] Adds test for author page bug --- bookwyrm/tests/views/test_author.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index ad5c069d..71daef2a 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -50,6 +50,43 @@ class AuthorViews(TestCase): models.SiteSettings.objects.create() def test_author_page(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + author = models.Author.objects.create(name="Jessica") + self.book.authors.add(author) + request = self.factory.get("") + request.user = self.local_user + with patch("bookwyrm.views.author.is_api_request") as is_api: + is_api.return_value = False + result = view(request, author.id) + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + + def test_author_page_edition_author(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + another_book = models.Edition.objects.create( + title="Example Edition", + remote_id="https://example.com/book/1", + parent_work=self.work, + isbn_13="9780300112511", + ) + author = models.Author.objects.create(name="Jessica") + self.book.authors.add(author) + request = self.factory.get("") + request.user = self.local_user + with patch("bookwyrm.views.author.is_api_request") as is_api: + is_api.return_value = False + result = view(request, author.id) + books = result.context_data["books"] + self.assertEqual(books.object_list.count(), 1) + + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + + def test_author_page_empty(self): """there are so many views, this just makes sure it LOADS""" view = views.Author.as_view() author = models.Author.objects.create(name="Jessica") From 49ceb2a9780035dc9b7a4634b18110cda7e3a485 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 19:41:21 -0800 Subject: [PATCH 3/4] Fixes warning in author view tests --- bookwyrm/views/author.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index b50653f9..c3e456ef 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -28,7 +28,7 @@ class Author(View): books = models.Work.objects.filter( Q(authors=author) | Q(editions__authors=author) - ).distinct() + ).order_by("-published_date").distinct() paginated = Paginator(books, PAGE_LENGTH) page = paginated.get_page(request.GET.get("page")) From a73960a0da25fba82f4a6fb4185f69d102b3a000 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Feb 2022 19:44:03 -0800 Subject: [PATCH 4/4] Python formatting --- bookwyrm/views/author.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index c3e456ef..b4eb7ef5 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -26,9 +26,11 @@ class Author(View): if is_api_request(request): return ActivitypubResponse(author.to_activity()) - books = models.Work.objects.filter( - Q(authors=author) | Q(editions__authors=author) - ).order_by("-published_date").distinct() + books = ( + models.Work.objects.filter(Q(authors=author) | Q(editions__authors=author)) + .order_by("-published_date") + .distinct() + ) paginated = Paginator(books, PAGE_LENGTH) page = paginated.get_page(request.GET.get("page"))