Merge pull request #1037 from bookwyrm-social/search-bug

Fixes error on empty search results
This commit is contained in:
Mouse Reeve 2021-05-03 10:57:53 -07:00 committed by GitHub
commit 7db8e249cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -127,7 +127,7 @@ class Views(TestCase):
response = view(request)
response.render()
self.assertEqual(response.context_data["results"].object_list.count(), 0)
self.assertFalse("results" in response.context_data)
def test_search_lists(self):
"""searches remote connectors"""

View file

@ -56,10 +56,11 @@ class Search(View):
results = endpoints[search_type](
query, request.user, min_confidence, search_remote
)
paginated = Paginator(results, PAGE_LENGTH).get_page(
request.GET.get("page")
)
data["results"] = paginated
if results:
paginated = Paginator(results, PAGE_LENGTH).get_page(
request.GET.get("page")
)
data["results"] = paginated
return TemplateResponse(request, "search/{:s}.html".format(search_type), data)