forked from mirrors/bookwyrm
List and user previews
This commit is contained in:
parent
21a5147c3c
commit
cb6c0035d7
5 changed files with 105 additions and 100 deletions
|
@ -1,7 +1,5 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
|
||||||
{% load humanize %}
|
|
||||||
|
|
||||||
{% block title %}{% trans "Directory" %}{% endblock %}
|
{% block title %}{% trans "Directory" %}{% endblock %}
|
||||||
|
|
||||||
|
@ -41,59 +39,7 @@
|
||||||
<div class="columns is-multiline">
|
<div class="columns is-multiline">
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<div class="column is-one-third">
|
<div class="column is-one-third">
|
||||||
<div class="card is-stretchable">
|
{% include 'directory/user_card.html' %}
|
||||||
<div class="card-content">
|
|
||||||
<div class="media">
|
|
||||||
<a href="{{ user.local_path }}" class="media-left">
|
|
||||||
{% include 'snippets/avatar.html' with user=user large=True %}
|
|
||||||
</a>
|
|
||||||
<div class="media-content">
|
|
||||||
<a href="{{ user.local_path }}" class="is-block mb-2">
|
|
||||||
<span class="title is-4 is-block">{{ user.display_name }}</span>
|
|
||||||
<span class="subtitle is-7 is-block">@{{ user|username }}</span>
|
|
||||||
</a>
|
|
||||||
{% include 'snippets/follow_button.html' with user=user %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% if user.summary %}
|
|
||||||
{{ user.summary | to_markdown | safe | truncatechars_html:40 }}
|
|
||||||
{% else %} {% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<footer class="card-footer">
|
|
||||||
{% if user != request.user %}
|
|
||||||
{% if user.mutuals %}
|
|
||||||
<div class="card-footer-item">
|
|
||||||
<div class="has-text-centered">
|
|
||||||
<p class="title is-6 mb-0">{{ user.mutuals }}</p>
|
|
||||||
<p class="help">{% blocktrans count counter=user.mutuals %}follower you follow{% plural %}followers you follow{% endblocktrans %}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% elif user.shared_books %}
|
|
||||||
<div class="card-footer-item">
|
|
||||||
<div class="has-text-centered">
|
|
||||||
<p class="title is-6 mb-0">{{ user.shared_books }}</p>
|
|
||||||
<p class="help">{% blocktrans count counter=user.shared_books %}book on your shelves{% plural %}books on your shelves{% endblocktrans %}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
<div class="card-footer-item">
|
|
||||||
<div class="has-text-centered">
|
|
||||||
<p class="title is-6 mb-0">{{ user.status_set.count|intword }}</p>
|
|
||||||
<p class="help">{% trans "posts" %}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer-item">
|
|
||||||
<div class="has-text-centered">
|
|
||||||
<p class="title is-6 mb-0">{{ user.last_active_date|naturalday }}</p>
|
|
||||||
<p class="help">{% trans "last active" %}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
57
bookwyrm/templates/directory/user_card.html
Normal file
57
bookwyrm/templates/directory/user_card.html
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% load bookwyrm_tags %}
|
||||||
|
{% load humanize %}
|
||||||
|
|
||||||
|
<div class="card is-stretchable">
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="media">
|
||||||
|
<a href="{{ user.local_path }}" class="media-left">
|
||||||
|
{% include 'snippets/avatar.html' with user=user large=True %}
|
||||||
|
</a>
|
||||||
|
<div class="media-content">
|
||||||
|
<a href="{{ user.local_path }}" class="is-block mb-2">
|
||||||
|
<span class="title is-4 is-block">{{ user.display_name }}</span>
|
||||||
|
<span class="subtitle is-7 is-block">@{{ user|username }}</span>
|
||||||
|
</a>
|
||||||
|
{% include 'snippets/follow_button.html' with user=user %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{% if user.summary %}
|
||||||
|
{{ user.summary | to_markdown | safe | truncatechars_html:40 }}
|
||||||
|
{% else %} {% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<footer class="card-footer">
|
||||||
|
{% if user != request.user %}
|
||||||
|
{% if user.mutuals %}
|
||||||
|
<div class="card-footer-item">
|
||||||
|
<div class="has-text-centered">
|
||||||
|
<p class="title is-6 mb-0">{{ user.mutuals }}</p>
|
||||||
|
<p class="help">{% blocktrans count counter=user.mutuals %}follower you follow{% plural %}followers you follow{% endblocktrans %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% elif user.shared_books %}
|
||||||
|
<div class="card-footer-item">
|
||||||
|
<div class="has-text-centered">
|
||||||
|
<p class="title is-6 mb-0">{{ user.shared_books }}</p>
|
||||||
|
<p class="help">{% blocktrans count counter=user.shared_books %}book on your shelves{% plural %}books on your shelves{% endblocktrans %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
<div class="card-footer-item">
|
||||||
|
<div class="has-text-centered">
|
||||||
|
<p class="title is-6 mb-0">{{ user.status_set.count|intword }}</p>
|
||||||
|
<p class="help">{% trans "posts" %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer-item">
|
||||||
|
<div class="has-text-centered">
|
||||||
|
<p class="title is-6 mb-0">{{ user.last_active_date|naturalday }}</p>
|
||||||
|
<p class="help">{% trans "last active" %}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
|
@ -33,6 +33,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% if query %}
|
||||||
<nav class="tabs">
|
<nav class="tabs">
|
||||||
<ul>
|
<ul>
|
||||||
<li{% if type == "book" %} class="is-active"{% endif %}>
|
<li{% if type == "book" %} class="is-active"{% endif %}>
|
||||||
|
@ -56,4 +57,6 @@
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
{% extends 'search/layout.html' %}
|
{% extends 'search/layout.html' %}
|
||||||
|
{% load bookwyrm_tags %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
{% for result in results %}
|
<div class="columns is-multiline">
|
||||||
hi
|
{% for user in results %}
|
||||||
|
<div class="column is-one-third">
|
||||||
|
{% include 'directory/user_card.html' %}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -43,24 +43,22 @@ class Search(View):
|
||||||
search_type = "book"
|
search_type = "book"
|
||||||
endpoint = endpoints[search_type]
|
endpoint = endpoints[search_type]
|
||||||
|
|
||||||
data = {"query": query or "", "type": search_type}
|
data = {
|
||||||
results = endpoint(query, request.user, min_confidence) if query else {}
|
"query": query or "",
|
||||||
|
"type": search_type,
|
||||||
|
"results": endpoint(query, request.user, min_confidence) if query else {},
|
||||||
|
}
|
||||||
|
|
||||||
return TemplateResponse(
|
return TemplateResponse(request, "search/{:s}.html".format(search_type), data)
|
||||||
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"""
|
"""the real business is elsewhere"""
|
||||||
|
return connector_manager.search(query, min_confidence=min_confidence)
|
||||||
return {
|
|
||||||
"results": connector_manager.search(query, min_confidence=min_confidence),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def user_search(query, viewer, _):
|
def user_search(query, viewer, _):
|
||||||
"""that search bar up top"""
|
"""cool kids members only user search"""
|
||||||
# logged out viewers can't search users
|
# logged out viewers can't search users
|
||||||
if not viewer.is_authenticated:
|
if not viewer.is_authenticated:
|
||||||
return {}
|
return {}
|
||||||
|
@ -70,41 +68,37 @@ def user_search(query, viewer, _):
|
||||||
if re.match(regex.full_username, query):
|
if re.match(regex.full_username, query):
|
||||||
handle_remote_webfinger(query)
|
handle_remote_webfinger(query)
|
||||||
|
|
||||||
return {
|
return (
|
||||||
"results": (
|
models.User.viewer_aware_objects(viewer)
|
||||||
models.User.viewer_aware_objects(viewer)
|
.annotate(
|
||||||
.annotate(
|
similarity=Greatest(
|
||||||
similarity=Greatest(
|
TrigramSimilarity("username", query),
|
||||||
TrigramSimilarity("username", query),
|
TrigramSimilarity("localname", query),
|
||||||
TrigramSimilarity("localname", query),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.filter(
|
)
|
||||||
similarity__gt=0.5,
|
.filter(
|
||||||
)
|
similarity__gt=0.5,
|
||||||
.order_by("-similarity")[:10]
|
)
|
||||||
),
|
.order_by("-similarity")[:10]
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
def list_search(query, viewer, _):
|
def list_search(query, viewer, _):
|
||||||
"""any relevent lists?"""
|
"""any relevent lists?"""
|
||||||
return {
|
return (
|
||||||
"results": (
|
privacy_filter(
|
||||||
privacy_filter(
|
viewer,
|
||||||
viewer,
|
models.List.objects,
|
||||||
models.List.objects,
|
privacy_levels=["public", "followers"],
|
||||||
privacy_levels=["public", "followers"],
|
)
|
||||||
|
.annotate(
|
||||||
|
similarity=Greatest(
|
||||||
|
TrigramSimilarity("name", query),
|
||||||
|
TrigramSimilarity("description", query),
|
||||||
)
|
)
|
||||||
.annotate(
|
)
|
||||||
similarity=Greatest(
|
.filter(
|
||||||
TrigramSimilarity("name", query),
|
similarity__gt=0.1,
|
||||||
TrigramSimilarity("description", query),
|
)
|
||||||
)
|
.order_by("-similarity")[:10]
|
||||||
)
|
)
|
||||||
.filter(
|
|
||||||
similarity__gt=0.1,
|
|
||||||
)
|
|
||||||
.order_by("-similarity")[:10]
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue