forked from mirrors/bookwyrm
Adds search templates
This commit is contained in:
parent
4b73c37126
commit
5ca9d2a7b0
7 changed files with 107 additions and 146 deletions
9
bookwyrm/templates/search/book.html
Normal file
9
bookwyrm/templates/search/book.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends 'search/layout.html' %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% for result in results %}
|
||||
hi
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
59
bookwyrm/templates/search/layout.html
Normal file
59
bookwyrm/templates/search/layout.html
Normal file
|
@ -0,0 +1,59 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Search" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="block">
|
||||
<h1 class="title">
|
||||
{% blocktrans %}Search{% endblocktrans %}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<form class="block">
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
<input type="input" class="input" value="{{ query }}">
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="select">
|
||||
<select>
|
||||
<option value="book" {% if type == "book" %}selected{% endif %}>{% trans "Books" %}</option>
|
||||
<option value="user" {% if type == "user" %}selected{% endif %}>{% trans "Users" %}</option>
|
||||
<option value="list" {% if type == "list" %}selected{% endif %}>{% trans "Lists" %}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-primary">
|
||||
<span>Search</span>
|
||||
<span class="icon icon-search" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<nav class="tabs">
|
||||
<ul>
|
||||
{% url 'search' "book" as url %}
|
||||
<li{% if request.path in url %} class="is-active"{% endif %}>
|
||||
<a href="{{ url }}">{% trans "Books" %}</a>
|
||||
</li>
|
||||
{% url 'search' "user" as url %}
|
||||
<li{% if url in request.path %} class="is-active"{% endif %}>
|
||||
<a href="{{ url }}">{% trans "Users" %}</a>
|
||||
</li>
|
||||
{% url 'search' "list" as url %}
|
||||
<li{% if url in request.path %} class="is-active"{% endif %}>
|
||||
<a href="{{ url }}">{% trans "Lists" %}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="block columns">
|
||||
<section class="block">
|
||||
{% block panel %}
|
||||
{% endblock %}
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
9
bookwyrm/templates/search/list.html
Normal file
9
bookwyrm/templates/search/list.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends 'search/layout.html' %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% for result in results %}
|
||||
hi
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
9
bookwyrm/templates/search/user.html
Normal file
9
bookwyrm/templates/search/user.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{% extends 'search/layout.html' %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% for result in results %}
|
||||
hi
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
|
@ -1,133 +0,0 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Search Results" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% with book_results|first as local_results %}
|
||||
<div class="block">
|
||||
<h1 class="title">{% blocktrans %}Search Results for "{{ query }}"{% endblocktrans %}</h1>
|
||||
</div>
|
||||
|
||||
<div class="block columns">
|
||||
<div class="column">
|
||||
<h2 class="title is-4">{% trans "Matching Books" %}</h2>
|
||||
<section class="block">
|
||||
{% if not local_results.results %}
|
||||
<p><em>{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}</em></p>
|
||||
{% if not user.is_authenticated %}
|
||||
<p>
|
||||
<a href="{% url 'login' %}">{% trans "Log in to import or add books." %}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<ul>
|
||||
{% for result in local_results.results %}
|
||||
<li class="pd-4">
|
||||
{% include 'snippets/search_result_text.html' with result=result %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
{% if book_results|slice:":1" and local_results.results %}
|
||||
<div class="block">
|
||||
<h3 class="title is-6">
|
||||
{% trans "Didn't find what you were looking for?" %}
|
||||
</h3>
|
||||
{% trans "Show results from other catalogues" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=button_text small=True controls_text="more-results" %}
|
||||
|
||||
{% if local_results.results %}
|
||||
{% trans "Hide results from other catalogues" as button_text %}
|
||||
{% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="{% if local_results.results %}is-hidden{% endif %}" id="more-results">
|
||||
{% for result_set in book_results|slice:"1:" %}
|
||||
{% if result_set.results %}
|
||||
<section class="box has-background-white-bis">
|
||||
{% if not result_set.connector.local %}
|
||||
<header class="columns is-mobile">
|
||||
<div class="column">
|
||||
<h3 class="title is-5">
|
||||
Results from
|
||||
<a href="{{ result_set.connector.base_url }}" target="_blank">{{ result_set.connector.name|default:result_set.connector.identifier }}</a>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
{% trans "Show" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=button_text small=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon="arrow-down" pressed=forloop.first %}
|
||||
</div>
|
||||
</header>
|
||||
{% endif %}
|
||||
|
||||
<div class="box has-background-white is-shadowless{% if not forloop.first %} is-hidden{% endif %}" id="more-results-panel-{{ result_set.connector.identifier }}">
|
||||
<div class="is-flex is-flex-direction-row-reverse">
|
||||
<div>
|
||||
{% trans "Close" as button_text %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with label=button_text class="delete" nonbutton=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier pressed=forloop.first %}
|
||||
</div>
|
||||
|
||||
<ul class="is-flex-grow-1">
|
||||
{% for result in result_set.results %}
|
||||
<li class="mb-5">
|
||||
{% include 'snippets/search_result_text.html' with result=result remote_result=True %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="block">
|
||||
<a href="/create-book">Manually add book</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="column">
|
||||
{% if request.user.is_authenticated %}
|
||||
<section class="box">
|
||||
<h2 class="title is-4">{% trans "Matching Users" %}</h2>
|
||||
{% if not user_results %}
|
||||
<p><em>{% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}</em></p>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% for result in user_results %}
|
||||
<li class="block">
|
||||
<a href="{{ result.local_path }}">
|
||||
{% include 'snippets/avatar.html' with user=result %}
|
||||
{{ result.display_name }}
|
||||
</a> ({{ result.username }})
|
||||
{% include 'snippets/follow_button.html' with user=result %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
{% endif %}
|
||||
<section class="box">
|
||||
<h2 class="title is-4">{% trans "Lists" %}</h2>
|
||||
{% if not list_results %}
|
||||
<p><em>{% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}</em></p>
|
||||
{% endif %}
|
||||
{% for result in list_results %}
|
||||
<div class="block">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="{% url 'list' result.id %}">{{ result.name }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endblock %}
|
|
@ -163,7 +163,8 @@ urlpatterns = [
|
|||
name="direct-messages-user",
|
||||
),
|
||||
# search
|
||||
re_path(r"^search/?$", views.Search.as_view()),
|
||||
re_path(r"^search/?$", views.Search.as_view(), name="search"),
|
||||
re_path(r"^search/(?P<search_type>user|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()),
|
||||
|
|
|
@ -30,15 +30,22 @@ class Search(View):
|
|||
)
|
||||
return JsonResponse([r.json() for r in book_results], safe=False)
|
||||
|
||||
data = {"query": query, "type": search_type}
|
||||
# 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)
|
||||
return TemplateResponse(request, "search_results.html", {**data, **results})
|
||||
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)
|
||||
|
||||
return TemplateResponse(
|
||||
request,
|
||||
"search/{:s}.html".format(search_type or "book"),
|
||||
{**data, **results}
|
||||
)
|
||||
|
||||
|
||||
def book_search(query, min_confidence):
|
||||
|
@ -46,7 +53,7 @@ def book_search(query, min_confidence):
|
|||
|
||||
return {
|
||||
"query": query or "",
|
||||
"book_results": connector_manager.search(query, min_confidence=min_confidence),
|
||||
"results": connector_manager.search(query, min_confidence=min_confidence),
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +70,7 @@ def user_search(query, viewer):
|
|||
|
||||
return {
|
||||
"query": query,
|
||||
"user_results": (
|
||||
"results": (
|
||||
models.User.viewer_aware_objects(viewer)
|
||||
.annotate(
|
||||
similarity=Greatest(
|
||||
|
@ -83,7 +90,7 @@ def list_search(query, viewer):
|
|||
"""any relevent lists?"""
|
||||
return {
|
||||
"query": query,
|
||||
"list_results": (
|
||||
"results": (
|
||||
privacy_filter(
|
||||
viewer,
|
||||
models.List.objects,
|
||||
|
|
Loading…
Reference in a new issue