From cb6c0035d7ee97ee531894e6227df22fffbb7700 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Fri, 30 Apr 2021 19:19:10 -0700
Subject: [PATCH] List and user previews
---
bookwyrm/templates/directory/directory.html | 56 +--------------
bookwyrm/templates/directory/user_card.html | 57 +++++++++++++++
bookwyrm/templates/search/layout.html | 3 +
bookwyrm/templates/search/user.html | 9 ++-
bookwyrm/views/search.py | 80 ++++++++++-----------
5 files changed, 105 insertions(+), 100 deletions(-)
create mode 100644 bookwyrm/templates/directory/user_card.html
diff --git a/bookwyrm/templates/directory/directory.html b/bookwyrm/templates/directory/directory.html
index 2fa8a5aea..f97a84814 100644
--- a/bookwyrm/templates/directory/directory.html
+++ b/bookwyrm/templates/directory/directory.html
@@ -1,7 +1,5 @@
{% extends 'layout.html' %}
{% load i18n %}
-{% load bookwyrm_tags %}
-{% load humanize %}
{% block title %}{% trans "Directory" %}{% endblock %}
@@ -41,59 +39,7 @@
{% for user in users %}
-
-
-
-
-
- {% if user.summary %}
- {{ user.summary | to_markdown | safe | truncatechars_html:40 }}
- {% else %} {% endif %}
-
-
-
-
+ {% include 'directory/user_card.html' %}
{% endfor %}
diff --git a/bookwyrm/templates/directory/user_card.html b/bookwyrm/templates/directory/user_card.html
new file mode 100644
index 000000000..8e7538c89
--- /dev/null
+++ b/bookwyrm/templates/directory/user_card.html
@@ -0,0 +1,57 @@
+{% load i18n %}
+{% load bookwyrm_tags %}
+{% load humanize %}
+
+
+
+
+
+
+ {% if user.summary %}
+ {{ user.summary | to_markdown | safe | truncatechars_html:40 }}
+ {% else %} {% endif %}
+
+
+
+
diff --git a/bookwyrm/templates/search/layout.html b/bookwyrm/templates/search/layout.html
index da0f651af..b122d7e25 100644
--- a/bookwyrm/templates/search/layout.html
+++ b/bookwyrm/templates/search/layout.html
@@ -33,6 +33,7 @@
+{% if query %}
{% endif %}
+{% endif %}
+
{% endblock %}
diff --git a/bookwyrm/templates/search/user.html b/bookwyrm/templates/search/user.html
index 5d66ef901..c6adc613a 100644
--- a/bookwyrm/templates/search/user.html
+++ b/bookwyrm/templates/search/user.html
@@ -1,9 +1,14 @@
{% extends 'search/layout.html' %}
+{% load bookwyrm_tags %}
{% block panel %}
-{% for result in results %}
-hi
+
+{% for user in results %}
+
+ {% include 'directory/user_card.html' %}
+
{% endfor %}
+
{% endblock %}
diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py
index cfbc1f0ba..603ed2117 100644
--- a/bookwyrm/views/search.py
+++ b/bookwyrm/views/search.py
@@ -43,24 +43,22 @@ class Search(View):
search_type = "book"
endpoint = endpoints[search_type]
- data = {"query": query or "", "type": search_type}
- results = endpoint(query, request.user, min_confidence) if query else {}
+ data = {
+ "query": query or "",
+ "type": search_type,
+ "results": endpoint(query, request.user, min_confidence) if query else {},
+ }
- return TemplateResponse(
- request, "search/{:s}.html".format(search_type), {**data, **results}
- )
+ return TemplateResponse(request, "search/{:s}.html".format(search_type), data)
def book_search(query, _, min_confidence):
- """that search bar up top"""
-
- return {
- "results": connector_manager.search(query, min_confidence=min_confidence),
- }
+ """the real business is elsewhere"""
+ return connector_manager.search(query, min_confidence=min_confidence)
def user_search(query, viewer, _):
- """that search bar up top"""
+ """cool kids members only user search"""
# logged out viewers can't search users
if not viewer.is_authenticated:
return {}
@@ -70,41 +68,37 @@ def user_search(query, viewer, _):
if re.match(regex.full_username, query):
handle_remote_webfinger(query)
- return {
- "results": (
- models.User.viewer_aware_objects(viewer)
- .annotate(
- similarity=Greatest(
- TrigramSimilarity("username", query),
- TrigramSimilarity("localname", query),
- )
+ return (
+ models.User.viewer_aware_objects(viewer)
+ .annotate(
+ similarity=Greatest(
+ TrigramSimilarity("username", query),
+ TrigramSimilarity("localname", query),
)
- .filter(
- similarity__gt=0.5,
- )
- .order_by("-similarity")[:10]
- ),
- }
+ )
+ .filter(
+ similarity__gt=0.5,
+ )
+ .order_by("-similarity")[:10]
+ )
def list_search(query, viewer, _):
"""any relevent lists?"""
- return {
- "results": (
- privacy_filter(
- viewer,
- models.List.objects,
- privacy_levels=["public", "followers"],
+ return (
+ privacy_filter(
+ viewer,
+ models.List.objects,
+ privacy_levels=["public", "followers"],
+ )
+ .annotate(
+ similarity=Greatest(
+ TrigramSimilarity("name", query),
+ TrigramSimilarity("description", query),
)
- .annotate(
- similarity=Greatest(
- TrigramSimilarity("name", query),
- TrigramSimilarity("description", query),
- )
- )
- .filter(
- similarity__gt=0.1,
- )
- .order_by("-similarity")[:10]
- ),
- }
+ )
+ .filter(
+ similarity__gt=0.1,
+ )
+ .order_by("-similarity")[:10]
+ )