From 611e7870e7707fe5d847e9bad589533acbc221f1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 12:36:53 -0800 Subject: [PATCH 1/8] Show publisher on book data page --- bookwyrm/templates/book.html | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index 16bf11972..ee1ea270b 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -78,13 +78,22 @@

- {% if book.physical_format and not book.pages %} - {{ book.physical_format | title }} - {% elif book.physical_format and book.pages %} - {% blocktrans with format=book.physical_format|title pages=book.pages %}{{ format }}, {{ pages }} pages{% endblocktrans %} - {% elif book.pages %} - {% blocktrans with pages=book.pages %}{{ pages }} pages{% endblocktrans %} - {% endif %} + {% if book.physical_format and not book.pages %} + {{ book.physical_format | title }} + {% elif book.physical_format and book.pages %} + {% blocktrans with format=book.physical_format|title pages=book.pages %}{{ format }}, {{ pages }} pages{% endblocktrans %} + {% elif book.pages %} + {% blocktrans with pages=book.pages %}{{ pages }} pages{% endblocktrans %} + {% endif %} +

+

+ {% if book.published_date and book.publishers %} + {% blocktrans with date=book.published_date|date:'M jS Y' publisher=book.publishers|join:', ' %}Published {{ date }} by {{ publisher }}.{% endblocktrans %} + {% elif book.published_date %} + {% blocktrans with date=book.published_date|date:'M jS Y' %}Published {{ date }}{% endblocktrans %} + {% else %} + {% blocktrans with publisher=book.publishers|join:', ' %}Published by {{ publisher }}.{% endblocktrans %} + {% endif %}

{% if book.openlibrary_key %} From 05fcfbc66f9662b66d020ee61d54bea3dfb009ba Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 13:55:20 -0800 Subject: [PATCH 2/8] Show more data about books in search --- bookwyrm/connectors/abstract_connector.py | 5 +-- bookwyrm/connectors/bookwyrm_connector.py | 3 +- bookwyrm/connectors/openlibrary.py | 9 +++-- bookwyrm/connectors/self_connector.py | 12 ++----- bookwyrm/management/commands/initdb.py | 4 +-- bookwyrm/templates/search_results.html | 9 ++--- .../snippets/search_result_text.html | 35 +++++++++++++++++-- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 4b118d64b..00b5c5c9e 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -262,9 +262,10 @@ class SearchResult: title: str key: str - author: str - year: str connector: object + author: str = None + year: str = None + cover: str = None confidence: int = 1 def __repr__(self): diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 742d7e858..f7869d55c 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -24,5 +24,4 @@ class Connector(AbstractMinimalConnector): return data def format_isbn_search_result(self, search_result): - search_result["connector"] = self - return SearchResult(**search_result) + return self.format_search_result(search_result) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index c83a65d6b..8df96526f 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -95,10 +95,12 @@ class Connector(AbstractConnector): url = "%s%s" % (self.base_url, author_id) yield self.get_or_create_author(url) - def get_cover_url(self, cover_blob): + def get_cover_url(self, cover_blob, size='L'): """ ask openlibrary for the cover """ + if not cover_blob: + return None cover_id = cover_blob[0] - image_name = "%s-L.jpg" % cover_id + image_name = "%s-%s.jpg" % (cover_id, size) return "%s/b/id/%s" % (self.covers_url, image_name) def parse_search_data(self, data): @@ -108,12 +110,15 @@ class Connector(AbstractConnector): # build the remote id from the openlibrary key key = self.books_url + search_result["key"] author = search_result.get("author_name") or ["Unknown"] + cover_blob = search_result.get("cover_i") + cover = self.get_cover_url([cover_blob], size='M') if cover_blob else None return SearchResult( title=search_result.get("title"), key=key, author=", ".join(author), connector=self, year=search_result.get("first_publish_year"), + cover=cover, ) def parse_isbn_search_data(self, data): diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 60acb59bd..10777b2b6 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -67,20 +67,12 @@ class Connector(AbstractConnector): if search_result.published_date else None, connector=self, + cover='%s%s' % (self.covers_url, search_result.cover), confidence=search_result.rank if hasattr(search_result, "rank") else 1, ) def format_isbn_search_result(self, search_result): - return SearchResult( - title=search_result.title, - key=search_result.remote_id, - author=search_result.author_text, - year=search_result.published_date.year - if search_result.published_date - else None, - connector=self, - confidence=search_result.rank if hasattr(search_result, "rank") else 1, - ) + return self.format_search_result(search_result) def is_work_data(self, data): pass diff --git a/bookwyrm/management/commands/initdb.py b/bookwyrm/management/commands/initdb.py index 6b3f3762e..d6101c877 100644 --- a/bookwyrm/management/commands/initdb.py +++ b/bookwyrm/management/commands/initdb.py @@ -76,7 +76,7 @@ def init_connectors(): connector_file="self_connector", base_url="https://%s" % DOMAIN, books_url="https://%s/book" % DOMAIN, - covers_url="https://%s/images/covers" % DOMAIN, + covers_url="https://%s/images/" % DOMAIN, search_url="https://%s/search?q=" % DOMAIN, isbn_search_url="https://%s/isbn/" % DOMAIN, priority=1, @@ -88,7 +88,7 @@ def init_connectors(): connector_file="bookwyrm_connector", base_url="https://bookwyrm.social", books_url="https://bookwyrm.social/book", - covers_url="https://bookwyrm.social/images/covers", + covers_url="https://bookwyrm.social/images/", search_url="https://bookwyrm.social/search?q=", isbn_search_url="https://bookwyrm.social/isbn/", priority=2, diff --git a/bookwyrm/templates/search_results.html b/bookwyrm/templates/search_results.html index 13497df83..6444cc184 100644 --- a/bookwyrm/templates/search_results.html +++ b/bookwyrm/templates/search_results.html @@ -19,7 +19,7 @@ @@ -50,12 +50,7 @@ diff --git a/bookwyrm/templates/snippets/search_result_text.html b/bookwyrm/templates/snippets/search_result_text.html index 360090509..059b8e7e8 100644 --- a/bookwyrm/templates/snippets/search_result_text.html +++ b/bookwyrm/templates/snippets/search_result_text.html @@ -1,3 +1,34 @@ {% load i18n %} -{% if link %}{{ result.title }}{% else %}{{ result.title }}{% endif %} -{% if result.author %} {% blocktrans with author=result.author %}by {{ author }}{% endblocktrans %}{% endif %}{% if result.year %} ({{ result.year }}){% endif %} +
+
+ {% if result.cover %} + + {% else %} +
+ +
+

{% trans "No cover" %}

+
+
+ {% endif %} +
+ +
+

+ + {{ result.title }} + + {% if result.author %} + {% blocktrans with author=result.author %}by {{ author }}{% endblocktrans %}{% endif %}{% if result.year %} ({{ result.year }}) + {% endif %} +

+ + {% if remote_result %} +
+ {% csrf_token %} + + +
+ {% endif %} +
+
From ad8257f8bddcb9b5b8d815d069db59ef9ca04405 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 14:04:41 -0800 Subject: [PATCH 3/8] Formats changes --- bookwyrm/connectors/openlibrary.py | 4 ++-- bookwyrm/connectors/self_connector.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 8df96526f..9be0266cd 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -95,7 +95,7 @@ class Connector(AbstractConnector): url = "%s%s" % (self.base_url, author_id) yield self.get_or_create_author(url) - def get_cover_url(self, cover_blob, size='L'): + def get_cover_url(self, cover_blob, size="L"): """ ask openlibrary for the cover """ if not cover_blob: return None @@ -111,7 +111,7 @@ class Connector(AbstractConnector): key = self.books_url + search_result["key"] author = search_result.get("author_name") or ["Unknown"] cover_blob = search_result.get("cover_i") - cover = self.get_cover_url([cover_blob], size='M') if cover_blob else None + cover = self.get_cover_url([cover_blob], size="M") if cover_blob else None return SearchResult( title=search_result.get("title"), key=key, diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 10777b2b6..500ffd74f 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -67,7 +67,7 @@ class Connector(AbstractConnector): if search_result.published_date else None, connector=self, - cover='%s%s' % (self.covers_url, search_result.cover), + cover="%s%s" % (self.covers_url, search_result.cover), confidence=search_result.rank if hasattr(search_result, "rank") else 1, ) From e9575cae6c295ccbe4175ca04e5fc90acf6701cc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 14:48:15 -0800 Subject: [PATCH 4/8] Buttons for undoing follow requests --- bookwyrm/templates/snippets/follow_button.html | 14 ++++++-------- bookwyrm/urls.py | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 419aa211b..eddf61cb1 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -1,18 +1,12 @@ {% load i18n %} {% if request.user == user or not request.user.is_authenticated %} -{% elif request.user in user.follower_requests.all %} - -
- {% trans "Follow request already sent." %} -
- {% elif user in request.user.blocks.all %} {% include 'snippets/block_button.html' %} {% else %}
- -
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index b645e943c..3ef2a79b8 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -188,8 +188,8 @@ urlpatterns = [ re_path(r"^start-reading/(?P\d+)/?$", views.start_reading), re_path(r"^finish-reading/(?P\d+)/?$", views.finish_reading), # following - re_path(r"^follow/?$", views.follow), - re_path(r"^unfollow/?$", views.unfollow), + re_path(r"^follow/?$", views.follow, name="follow"), + re_path(r"^unfollow/?$", views.unfollow, name="unfollow"), re_path(r"^accept-follow-request/?$", views.accept_follow_request), re_path(r"^delete-follow-request/?$", views.delete_follow_request), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From 4d7364d045ac27fa5bfa4cfe1375728a7e6c132e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 14:55:09 -0800 Subject: [PATCH 5/8] Undo follow request view --- .../templates/snippets/follow_button.html | 2 +- bookwyrm/views/follow.py | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index eddf61cb1..3df85a1a6 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -18,7 +18,7 @@