diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 6b1d2f8ca..10a633b2d 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -6,7 +6,7 @@ from .abstract_connector import AbstractMinimalConnector, SearchResult class Connector(AbstractMinimalConnector): """this is basically just for search""" - def get_or_create_book(self, remote_id, work=None): + def get_or_create_book(self, remote_id): return activitypub.resolve_remote_id(remote_id, model=models.Edition) def parse_search_data(self, data): diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 6b1b349fe..a8f858345 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -69,6 +69,10 @@ class Connector(AbstractConnector): return search_results def format_search_result(self, search_result): + cover = None + if search_result.cover: + cover = "%s%s" % (self.covers_url, search_result.cover) + return SearchResult( title=search_result.title, key=search_result.remote_id, @@ -77,7 +81,7 @@ class Connector(AbstractConnector): if search_result.published_date else None, connector=self, - cover="%s%s" % (self.covers_url, search_result.cover), + cover=cover, confidence=search_result.rank if hasattr(search_result, "rank") else 1, ) diff --git a/bookwyrm/templates/search_results.html b/bookwyrm/templates/search_results.html index 4c9c23dae..337e88f87 100644 --- a/bookwyrm/templates/search_results.html +++ b/bookwyrm/templates/search_results.html @@ -11,10 +11,15 @@
-

{% trans "Matching Books" %}

+

{% trans "Matching Books" %}

{% if not local_results.results %} -

{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}

+

{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}

+ {% if not user.is_authenticated %} +

+ {% trans "Log in to import or add books." %} +

+ {% endif %} {% else %}
    {% for result in local_results.results %} @@ -29,39 +34,56 @@ {% if request.user.is_authenticated %} {% if book_results|slice:":1" and local_results.results %}
    -

    +

    {% trans "Didn't find what you were looking for?" %} -

    +

    {% 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 %}
    {% endif %}
    {% for result_set in book_results|slice:"1:" %} {% if result_set.results %} -
    +
    {% if not result_set.connector.local %} -

    - Results from {% if result_set.connector.name %}{{ result_set.connector.name }}{% else %}{{ result_set.connector.identifier }}{% endif %} -

    +
    + +
    + {% 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 %} +
    +
    {% endif %} -
      - {% for result in result_set.results %} -
    • - {% include 'snippets/search_result_text.html' with result=result remote_result=True %} -
    • - {% endfor %} -
    +
    +
    +
    + {% 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 %} +
    +
      + {% for result in result_set.results %} +
    • + {% include 'snippets/search_result_text.html' with result=result remote_result=True %} +
    • + {% endfor %} +
    +
    +
    {% endif %} {% endfor %} - - {% 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 %}
    @@ -70,10 +92,11 @@ {% endif %}
    -
    -

    {% trans "Matching Users" %}

    + {% if request.user.is_authenticated %} +
    +

    {% trans "Matching Users" %}

    {% if not user_results %} -

    {% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}

    +

    {% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}

    {% endif %}
      {% for result in user_results %} @@ -87,10 +110,11 @@ {% endfor %}
    -
    -

    {% trans "Lists" %}

    + {% endif %} +
    +

    {% trans "Lists" %}

    {% if not list_results %} -

    {% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}

    +

    {% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}

    {% endif %} {% for result in list_results %}
    diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 53ceeaa83..24c80b046 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -43,7 +43,7 @@ urlpatterns = [ re_path("^api/updates/notifications/?$", views.get_notification_count), re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_count), # authentication - re_path(r"^login/?$", views.Login.as_view()), + re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^register/?$", views.Register.as_view()), re_path(r"^logout/?$", views.Logout.as_view()), re_path(r"^password-reset/?$", views.PasswordResetRequest.as_view()), diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py index 4543b55ee..bd5ac3c74 100644 --- a/bookwyrm/views/search.py +++ b/bookwyrm/views/search.py @@ -30,27 +30,30 @@ class Search(View): ) return JsonResponse([r.json() for r in book_results], safe=False) + data = {"query": query or ""} + # use webfinger for mastodon style account@domain.com username if query and re.match(regex.full_username, query): handle_remote_webfinger(query) # do a user search - user_results = ( - models.User.viewer_aware_objects(request.user) - .annotate( - similarity=Greatest( - TrigramSimilarity("username", query), - TrigramSimilarity("localname", query), + if request.user.is_authenticated: + data["user_results"] = ( + models.User.viewer_aware_objects(request.user) + .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] - ) # any relevent lists? - list_results = ( + data["list_results"] = ( privacy_filter( request.user, models.List.objects, @@ -68,11 +71,7 @@ class Search(View): .order_by("-similarity")[:10] ) - book_results = connector_manager.search(query, min_confidence=min_confidence) - data = { - "book_results": book_results, - "user_results": user_results, - "list_results": list_results, - "query": query or "", - } + data["book_results"] = connector_manager.search( + query, min_confidence=min_confidence + ) return TemplateResponse(request, "search_results.html", data) diff --git a/locale/de_DE/LC_MESSAGES/django.po b/locale/de_DE/LC_MESSAGES/django.po index bbdd13275..d7ad8724e 100644 --- a/locale/de_DE/LC_MESSAGES/django.po +++ b/locale/de_DE/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-29 11:36-0700\n" +"POT-Creation-Date: 2021-04-29 13:24-0700\n" "PO-Revision-Date: 2021-03-02 17:19-0800\n" "Last-Translator: Mouse Reeve \n" "Language-Team: English \n" @@ -282,7 +282,7 @@ msgstr "Orte" #: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65 #: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12 -#: bookwyrm/templates/search_results.html:91 +#: bookwyrm/templates/search_results.html:115 #: bookwyrm/templates/user/user_layout.html:62 msgid "Lists" msgstr "Listen" @@ -581,6 +581,7 @@ msgstr "Veröffentlicht von %(publisher)s." #: bookwyrm/templates/feed/feed_layout.html:70 #: bookwyrm/templates/get_started/layout.html:19 #: bookwyrm/templates/get_started/layout.html:52 +#: bookwyrm/templates/search_results.html:72 msgid "Close" msgstr "Schließen" @@ -1129,7 +1130,7 @@ msgid "Search for a user" msgstr "Suche nach Buch oder Benutzer*in" #: bookwyrm/templates/get_started/users.html:13 -#: bookwyrm/templates/search_results.html:76 +#: bookwyrm/templates/search_results.html:99 #, python-format msgid "No users found for \"%(query)s\"" msgstr "Keine Nutzer*innen für \"%(query)s\" gefunden" @@ -1908,23 +1909,33 @@ msgstr "Profil" msgid "Relationships" msgstr "Beziehungen" -#: bookwyrm/templates/search_results.html:33 +#: bookwyrm/templates/search_results.html:20 +msgid "Log in to import or add books." +msgstr "" + +#: bookwyrm/templates/search_results.html:38 msgid "Didn't find what you were looking for?" msgstr "Nicht gefunden, wonach du gesucht hast?" -#: bookwyrm/templates/search_results.html:35 +#: bookwyrm/templates/search_results.html:40 msgid "Show results from other catalogues" msgstr "Ergebnisse aus anderen Katalogen zeigen" -#: bookwyrm/templates/search_results.html:62 +#: bookwyrm/templates/search_results.html:44 msgid "Hide results from other catalogues" msgstr "Ergebnisse aus anderen Katalogen ausblenden" -#: bookwyrm/templates/search_results.html:74 +#: bookwyrm/templates/search_results.html:63 +#, fuzzy +#| msgid "Show more" +msgid "Show" +msgstr "Mehr anzeigen" + +#: bookwyrm/templates/search_results.html:97 msgid "Matching Users" msgstr "Passende Nutzer*innen" -#: bookwyrm/templates/search_results.html:93 +#: bookwyrm/templates/search_results.html:117 #, python-format msgid "No lists found for \"%(query)s\"" msgstr "Keine Liste für \"%(query)s\" gefunden" diff --git a/locale/en_US/LC_MESSAGES/django.po b/locale/en_US/LC_MESSAGES/django.po index 3637bb770..c3df47ae1 100644 --- a/locale/en_US/LC_MESSAGES/django.po +++ b/locale/en_US/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-29 11:36-0700\n" +"POT-Creation-Date: 2021-04-29 13:24-0700\n" "PO-Revision-Date: 2021-02-28 17:19-0800\n" "Last-Translator: Mouse Reeve \n" "Language-Team: English \n" @@ -261,7 +261,7 @@ msgstr "" #: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65 #: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12 -#: bookwyrm/templates/search_results.html:91 +#: bookwyrm/templates/search_results.html:115 #: bookwyrm/templates/user/user_layout.html:62 msgid "Lists" msgstr "" @@ -535,6 +535,7 @@ msgstr "" #: bookwyrm/templates/feed/feed_layout.html:70 #: bookwyrm/templates/get_started/layout.html:19 #: bookwyrm/templates/get_started/layout.html:52 +#: bookwyrm/templates/search_results.html:72 msgid "Close" msgstr "" @@ -1032,7 +1033,7 @@ msgid "Search for a user" msgstr "" #: bookwyrm/templates/get_started/users.html:13 -#: bookwyrm/templates/search_results.html:76 +#: bookwyrm/templates/search_results.html:99 #, python-format msgid "No users found for \"%(query)s\"" msgstr "" @@ -1739,23 +1740,31 @@ msgstr "" msgid "Relationships" msgstr "" -#: bookwyrm/templates/search_results.html:33 +#: bookwyrm/templates/search_results.html:20 +msgid "Log in to import or add books." +msgstr "" + +#: bookwyrm/templates/search_results.html:38 msgid "Didn't find what you were looking for?" msgstr "" -#: bookwyrm/templates/search_results.html:35 +#: bookwyrm/templates/search_results.html:40 msgid "Show results from other catalogues" msgstr "" -#: bookwyrm/templates/search_results.html:62 +#: bookwyrm/templates/search_results.html:44 msgid "Hide results from other catalogues" msgstr "" -#: bookwyrm/templates/search_results.html:74 +#: bookwyrm/templates/search_results.html:63 +msgid "Show" +msgstr "" + +#: bookwyrm/templates/search_results.html:97 msgid "Matching Users" msgstr "" -#: bookwyrm/templates/search_results.html:93 +#: bookwyrm/templates/search_results.html:117 #, python-format msgid "No lists found for \"%(query)s\"" msgstr "" diff --git a/locale/es/LC_MESSAGES/django.po b/locale/es/LC_MESSAGES/django.po index 8385f7f66..dab4c486f 100644 --- a/locale/es/LC_MESSAGES/django.po +++ b/locale/es/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-29 11:36-0700\n" +"POT-Creation-Date: 2021-04-29 13:24-0700\n" "PO-Revision-Date: 2021-03-19 11:49+0800\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -266,7 +266,7 @@ msgstr "Lugares" #: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65 #: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12 -#: bookwyrm/templates/search_results.html:91 +#: bookwyrm/templates/search_results.html:115 #: bookwyrm/templates/user/user_layout.html:62 msgid "Lists" msgstr "Listas" @@ -548,6 +548,7 @@ msgstr "Publicado por %(publisher)s." #: bookwyrm/templates/feed/feed_layout.html:70 #: bookwyrm/templates/get_started/layout.html:19 #: bookwyrm/templates/get_started/layout.html:52 +#: bookwyrm/templates/search_results.html:72 msgid "Close" msgstr "Cerrar" @@ -1060,7 +1061,7 @@ msgid "Search for a user" msgstr "Buscar un usuario" #: bookwyrm/templates/get_started/users.html:13 -#: bookwyrm/templates/search_results.html:76 +#: bookwyrm/templates/search_results.html:99 #, python-format msgid "No users found for \"%(query)s\"" msgstr "No se encontró ningún usuario correspondiente a \"%(query)s\"" @@ -1811,23 +1812,33 @@ msgstr "Perfil" msgid "Relationships" msgstr "Relaciones" -#: bookwyrm/templates/search_results.html:33 +#: bookwyrm/templates/search_results.html:20 +msgid "Log in to import or add books." +msgstr "" + +#: bookwyrm/templates/search_results.html:38 msgid "Didn't find what you were looking for?" msgstr "¿No encontraste lo que buscabas?" -#: bookwyrm/templates/search_results.html:35 +#: bookwyrm/templates/search_results.html:40 msgid "Show results from other catalogues" msgstr "Mostrar resultados de otros catálogos" -#: bookwyrm/templates/search_results.html:62 +#: bookwyrm/templates/search_results.html:44 msgid "Hide results from other catalogues" msgstr "Ocultar resultados de otros catálogos" -#: bookwyrm/templates/search_results.html:74 +#: bookwyrm/templates/search_results.html:63 +#, fuzzy +#| msgid "Show more" +msgid "Show" +msgstr "Mostrar más" + +#: bookwyrm/templates/search_results.html:97 msgid "Matching Users" msgstr "Usuarios correspondientes" -#: bookwyrm/templates/search_results.html:93 +#: bookwyrm/templates/search_results.html:117 #, python-format msgid "No lists found for \"%(query)s\"" msgstr "No se encontró ningúna lista correspondiente a \"%(query)s\"" diff --git a/locale/fr_FR/LC_MESSAGES/django.po b/locale/fr_FR/LC_MESSAGES/django.po index ee7a55344..01963e467 100644 --- a/locale/fr_FR/LC_MESSAGES/django.po +++ b/locale/fr_FR/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-29 11:36-0700\n" +"POT-Creation-Date: 2021-04-29 13:24-0700\n" "PO-Revision-Date: 2021-04-05 12:44+0100\n" "Last-Translator: Fabien Basmaison \n" "Language-Team: Mouse Reeve \n" @@ -272,7 +272,7 @@ msgstr "Lieux" #: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65 #: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12 -#: bookwyrm/templates/search_results.html:91 +#: bookwyrm/templates/search_results.html:115 #: bookwyrm/templates/user/user_layout.html:62 msgid "Lists" msgstr "Listes" @@ -554,6 +554,7 @@ msgstr "Publié par %(publisher)s." #: bookwyrm/templates/feed/feed_layout.html:70 #: bookwyrm/templates/get_started/layout.html:19 #: bookwyrm/templates/get_started/layout.html:52 +#: bookwyrm/templates/search_results.html:72 msgid "Close" msgstr "Fermer" @@ -1072,7 +1073,7 @@ msgid "Search for a user" msgstr "Chercher un compte" #: bookwyrm/templates/get_started/users.html:13 -#: bookwyrm/templates/search_results.html:76 +#: bookwyrm/templates/search_results.html:99 #, python-format msgid "No users found for \"%(query)s\"" msgstr "Aucun compte trouvé pour « %(query)s »" @@ -1836,23 +1837,33 @@ msgstr "Profil" msgid "Relationships" msgstr "Relations" -#: bookwyrm/templates/search_results.html:33 +#: bookwyrm/templates/search_results.html:20 +msgid "Log in to import or add books." +msgstr "" + +#: bookwyrm/templates/search_results.html:38 msgid "Didn't find what you were looking for?" msgstr "Vous n’avez pas trouvé ce que vous cherchiez ?" -#: bookwyrm/templates/search_results.html:35 +#: bookwyrm/templates/search_results.html:40 msgid "Show results from other catalogues" msgstr "Montrer les résultats d’autres catalogues" -#: bookwyrm/templates/search_results.html:62 +#: bookwyrm/templates/search_results.html:44 msgid "Hide results from other catalogues" msgstr "Masquer les résultats d’autres catalogues" -#: bookwyrm/templates/search_results.html:74 +#: bookwyrm/templates/search_results.html:63 +#, fuzzy +#| msgid "Show more" +msgid "Show" +msgstr "Déplier" + +#: bookwyrm/templates/search_results.html:97 msgid "Matching Users" msgstr "Comptes correspondants" -#: bookwyrm/templates/search_results.html:93 +#: bookwyrm/templates/search_results.html:117 #, python-format msgid "No lists found for \"%(query)s\"" msgstr "Aucune liste trouvée pour « %(query)s »" diff --git a/locale/zh_Hans/LC_MESSAGES/django.po b/locale/zh_Hans/LC_MESSAGES/django.po index af3bc59bd..783fc70ab 100644 --- a/locale/zh_Hans/LC_MESSAGES/django.po +++ b/locale/zh_Hans/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-29 11:36-0700\n" +"POT-Creation-Date: 2021-04-29 13:24-0700\n" "PO-Revision-Date: 2021-03-20 00:56+0000\n" "Last-Translator: Kana \n" "Language-Team: Mouse Reeve \n" @@ -270,7 +270,7 @@ msgstr "地点" #: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65 #: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12 -#: bookwyrm/templates/search_results.html:91 +#: bookwyrm/templates/search_results.html:115 #: bookwyrm/templates/user/user_layout.html:62 msgid "Lists" msgstr "列表" @@ -552,6 +552,7 @@ msgstr "由 %(publisher)s 出版。" #: bookwyrm/templates/feed/feed_layout.html:70 #: bookwyrm/templates/get_started/layout.html:19 #: bookwyrm/templates/get_started/layout.html:52 +#: bookwyrm/templates/search_results.html:72 msgid "Close" msgstr "关闭" @@ -1052,7 +1053,7 @@ msgid "Search for a user" msgstr "搜索用户" #: bookwyrm/templates/get_started/users.html:13 -#: bookwyrm/templates/search_results.html:76 +#: bookwyrm/templates/search_results.html:99 #, python-format msgid "No users found for \"%(query)s\"" msgstr "没有找到 \"%(query)s\" 的用户" @@ -1801,23 +1802,33 @@ msgstr "个人资料" msgid "Relationships" msgstr "关系" -#: bookwyrm/templates/search_results.html:33 +#: bookwyrm/templates/search_results.html:20 +msgid "Log in to import or add books." +msgstr "" + +#: bookwyrm/templates/search_results.html:38 msgid "Didn't find what you were looking for?" msgstr "没有找到你想找的?" -#: bookwyrm/templates/search_results.html:35 +#: bookwyrm/templates/search_results.html:40 msgid "Show results from other catalogues" msgstr "显示其它类别的结果" -#: bookwyrm/templates/search_results.html:62 +#: bookwyrm/templates/search_results.html:44 msgid "Hide results from other catalogues" msgstr "隐藏其它类别的结果" -#: bookwyrm/templates/search_results.html:74 +#: bookwyrm/templates/search_results.html:63 +#, fuzzy +#| msgid "Show more" +msgid "Show" +msgstr "显示更多" + +#: bookwyrm/templates/search_results.html:97 msgid "Matching Users" msgstr "匹配的用户" -#: bookwyrm/templates/search_results.html:93 +#: bookwyrm/templates/search_results.html:117 #, python-format msgid "No lists found for \"%(query)s\"" msgstr "没有找到 \"%(query)s\" 的列表"