mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-04 23:36:32 +00:00
Revamps search page
still needs to expand user search to do database lookups
This commit is contained in:
parent
a6d436d05d
commit
4ba9b7a119
3 changed files with 62 additions and 13 deletions
45
bookwyrm/templates/search_results.html
Normal file
45
bookwyrm/templates/search_results.html
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="block columns">
|
||||||
|
<div class="column">
|
||||||
|
<h2 class="title">Matching Books</h2>
|
||||||
|
{% for result_set in book_results %}
|
||||||
|
{% if result_set.results %}
|
||||||
|
<section>
|
||||||
|
{% if not result_set.connector.local %}
|
||||||
|
<h3>
|
||||||
|
Results from <a href="{{ result_set.connector.base_url }}" target="_blank">{% if result_set.connector.name %}{{ result_set.connector.name }}{% else %}{{ result_set.connector.identifier }}{% endif %}</a>
|
||||||
|
</h3>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for result in result_set.results %}
|
||||||
|
<div>
|
||||||
|
<form action="/resolve_book" method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="remote_id" value="{{ result.key }}">
|
||||||
|
<button type="submit">{{ result.title }} by {{ result.author }} ({{ result.year }})</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if not results %}
|
||||||
|
<p>No books found for "{{ query }}"</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<h2 class="title">Matching Users</h2>
|
||||||
|
{% if not user_results %}
|
||||||
|
<p>No users found for "{{ query }}"</p>
|
||||||
|
{% endif %}
|
||||||
|
{% for result in user_results %}
|
||||||
|
<div class="block">
|
||||||
|
{% include 'snippets/avatar.html' with user=result %}</h2>
|
||||||
|
{% include 'snippets/username.html' with user=result show_full=True %}</h2>
|
||||||
|
{% include 'snippets/follow_button.html' with user=result %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -6,6 +6,7 @@
|
||||||
<p>No results found for "{{ query }}"</p>
|
<p>No results found for "{{ query }}"</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
|
{{ result }}
|
||||||
<div class="block">
|
<div class="block">
|
||||||
{% include 'snippets/avatar.html' with user=result %}</h2>
|
{% include 'snippets/avatar.html' with user=result %}</h2>
|
||||||
{% include 'snippets/username.html' with user=result show_full=True %}</h2>
|
{% include 'snippets/username.html' with user=result show_full=True %}</h2>
|
||||||
|
|
|
@ -147,22 +147,25 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
||||||
def search(request):
|
def search(request):
|
||||||
''' that search bar up top '''
|
''' that search bar up top '''
|
||||||
query = request.GET.get('q')
|
query = request.GET.get('q')
|
||||||
if re.match(r'\w+@\w+.\w+', query):
|
|
||||||
# if something looks like a username, search with webfinger
|
|
||||||
results = outgoing.handle_account_search(query)
|
|
||||||
return TemplateResponse(
|
|
||||||
request, 'user_results.html', {'results': results, 'query': query}
|
|
||||||
)
|
|
||||||
|
|
||||||
# or just send the question over to book search
|
|
||||||
|
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
# only return local results via json so we don't cause a cascade
|
# only return local book results via json so we don't cause a cascade
|
||||||
results = books_manager.local_search(query)
|
book_results = books_manager.local_search(query)
|
||||||
return JsonResponse([r.__dict__ for r in results], safe=False)
|
return JsonResponse([r.__dict__ for r in book_results], safe=False)
|
||||||
|
|
||||||
results = books_manager.search(query)
|
user_results = []
|
||||||
return TemplateResponse(request, 'book_results.html', {'results': results})
|
# use webfinger looks like a mastodon style account@domain.com username
|
||||||
|
if re.match(r'\w+@\w+.\w+', query):
|
||||||
|
# if something looks like a username, search with webfinger
|
||||||
|
user_results = outgoing.handle_remote_webfinger(query)
|
||||||
|
|
||||||
|
book_results = books_manager.search(query)
|
||||||
|
data = {
|
||||||
|
'book_results': book_results,
|
||||||
|
'user_results': user_results,
|
||||||
|
'query': query,
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'search_results.html', data)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue