diff --git a/bookwyrm/templates/search/layout.html b/bookwyrm/templates/search/layout.html index 005cda9d..da0f651a 100644 --- a/bookwyrm/templates/search/layout.html +++ b/bookwyrm/templates/search/layout.html @@ -10,14 +10,14 @@ -
+
- +
- @@ -35,25 +35,25 @@ -
-
- {% block panel %} - {% endblock %} -
-
+
+ {% block panel %} + {% endblock %} + {% if not results %} +

+ {% blocktrans %}No results found for "{{ query }}"{% endblocktrans %} +

+ {% endif %} +
{% endblock %} diff --git a/bookwyrm/templates/search/list.html b/bookwyrm/templates/search/list.html index 5d66ef90..d7e48f51 100644 --- a/bookwyrm/templates/search/list.html +++ b/bookwyrm/templates/search/list.html @@ -2,8 +2,6 @@ {% block panel %} -{% for result in results %} -hi -{% endfor %} +{% include 'lists/list_items.html' with lists=results %} {% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index a06e0bd4..5412378e 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -164,7 +164,6 @@ urlpatterns = [ ), # search re_path(r"^search/?$", views.Search.as_view(), name="search"), - re_path(r"^search/(?Puser|list|book)/?$", views.Search.as_view(), name="search"), # imports re_path(r"^import/?$", views.Import.as_view()), re_path(r"^import/(\d+)/?$", views.ImportStatus.as_view()), diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py index aaca7377..cfbc1f0b 100644 --- a/bookwyrm/views/search.py +++ b/bookwyrm/views/search.py @@ -18,10 +18,11 @@ from .helpers import handle_remote_webfinger class Search(View): """search users or books""" - def get(self, request, search_type=None): + def get(self, request): """that search bar up top""" query = request.GET.get("q") min_confidence = request.GET.get("min_confidence", 0.1) + search_type = request.GET.get("type") if is_api_request(request): # only return local book results via json so we don't cascade @@ -30,38 +31,39 @@ class Search(View): ) return JsonResponse([r.json() for r in book_results], safe=False) + if not search_type: + search_type = "user" if "@" in query else "book" + + endpoints = { + "book": book_search, + "user": user_search, + "list": list_search, + } + if not search_type in endpoints: + search_type = "book" + endpoint = endpoints[search_type] + data = {"query": query or "", "type": search_type} - results = {} - if query: - # make a guess about what type of query this is for - if search_type == "user" or (not search_type and "@" in query): - results = user_search(query, request.user) - elif search_type == "list": - results = list_search(query, request.user) - else: - results = book_search(query, min_confidence) + results = endpoint(query, request.user, min_confidence) if query else {} return TemplateResponse( - request, - "search/{:s}.html".format(search_type or "book"), - {**data, **results} + request, "search/{:s}.html".format(search_type), {**data, **results} ) -def book_search(query, min_confidence): +def book_search(query, _, min_confidence): """that search bar up top""" return { - "query": query or "", "results": connector_manager.search(query, min_confidence=min_confidence), } -def user_search(query, viewer): +def user_search(query, viewer, _): """that search bar up top""" # logged out viewers can't search users if not viewer.is_authenticated: - return None + return {} # use webfinger for mastodon style account@domain.com username to load the user if # they don't exist locally (handle_remote_webfinger will check the db) @@ -69,7 +71,6 @@ def user_search(query, viewer): handle_remote_webfinger(query) return { - "query": query, "results": ( models.User.viewer_aware_objects(viewer) .annotate( @@ -86,10 +87,9 @@ def user_search(query, viewer): } -def list_search(query, viewer): +def list_search(query, viewer, _): """any relevent lists?""" return { - "query": query, "results": ( privacy_filter( viewer,