From 0d7ffbc1753c78633cd36133d9d68b9d0e28758b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 11:34:59 -0700 Subject: [PATCH 1/7] Hide user status tabs when there are none --- bookwyrm/templates/book/book.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 980061840..889a031ea 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -249,6 +249,7 @@
{% if request.user.is_authenticated %} + {% if user_statuses.review_count or user_statuses.comment_count or user_stuatses.quotation_count %} {% endif %} + {% endif %} {% for review in statuses %}
Date: Fri, 30 Apr 2021 11:47:28 -0700 Subject: [PATCH 2/7] Removes set goal link from user page It's already in the tabs --- bookwyrm/templates/user/user.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bookwyrm/templates/user/user.html b/bookwyrm/templates/user/user.html index a97d26ab8..8002a2548 100644 --- a/bookwyrm/templates/user/user.html +++ b/bookwyrm/templates/user/user.html @@ -53,11 +53,6 @@

{% now 'Y' %} Reading Goal

{% include 'snippets/goal_progress.html' with goal=goal %}
-{% elif user == request.user %} - {% endif %}
From 57454afa4284c2ad805d41f0c5dc7d335dfca532 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 12:02:19 -0700 Subject: [PATCH 3/7] Creates visual separation between reading activity and reviews --- bookwyrm/templates/book/book.html | 6 +++++- bookwyrm/templates/snippets/readthrough.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 889a031ea..20e4d8127 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -155,9 +155,12 @@
{% if user_authenticated %} +
-

{% trans "Your reading activity" %}

+
+

{% trans "Your reading activity" %}

+
{% trans "Add read dates" as button_text %} {% include 'snippets/toggle/open_button.html' with text=button_text icon="plus" class="is-small" controls_text="add-readthrough" %} @@ -184,6 +187,7 @@ {% include 'snippets/readthrough.html' with readthrough=readthrough %} {% endfor %}
+
{% include 'snippets/create_status.html' with book=book hide_cover=True %} diff --git a/bookwyrm/templates/snippets/readthrough.html b/bookwyrm/templates/snippets/readthrough.html index a240a8215..cebdc2cd6 100644 --- a/bookwyrm/templates/snippets/readthrough.html +++ b/bookwyrm/templates/snippets/readthrough.html @@ -1,7 +1,7 @@ {% load i18n %} {% load humanize %} {% load tz %} -
+
From 900e7feb1b0a72071349c4bc72af44955d368254 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 12:06:21 -0700 Subject: [PATCH 4/7] Moved reviews into center column on books page --- bookwyrm/templates/book/book.html | 152 +++++++++++++++--------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 20e4d8127..40da64861 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -193,6 +193,82 @@ {% include 'snippets/create_status.html' with book=book hide_cover=True %}
{% endif %} +
+ {% if request.user.is_authenticated %} + {% if user_statuses.review_count or user_statuses.comment_count or user_stuatses.quotation_count %} + + {% endif %} + {% endif %} + + {% for review in statuses %} +
+ {% with status=review hide_book=True depth=1 %} + {% include 'snippets/status/status.html' %} + {% endwith %} +
+ {% endfor %} + +
+ {% for rating in ratings %} + {% with user=rating.user %} +
+
+
+ {% include 'snippets/avatar.html' %} +
+ +
+ +
+

{% trans "rated it" %}

+ + {% include 'snippets/stars.html' with rating=rating.rating %} +
+ +
+
+
+ {% endwith %} + {% endfor %} +
+
+ {% include 'snippets/pagination.html' with page=statuses path=request.path anchor="#reviews" %} +
+
{% if book.subjects %} @@ -251,82 +327,6 @@
-
- {% if request.user.is_authenticated %} - {% if user_statuses.review_count or user_statuses.comment_count or user_stuatses.quotation_count %} - - {% endif %} - {% endif %} - - {% for review in statuses %} -
- {% with status=review hide_book=True depth=1 %} - {% include 'snippets/status/status.html' %} - {% endwith %} -
- {% endfor %} - -
- {% for rating in ratings %} - {% with user=rating.user %} -
-
-
- {% include 'snippets/avatar.html' %} -
- -
- -
-

{% trans "rated it" %}

- - {% include 'snippets/stars.html' with rating=rating.rating %} -
- -
-
-
- {% endwith %} - {% endfor %} -
-
- {% include 'snippets/pagination.html' with page=statuses path=request.path anchor="#reviews" %} -
-
{% endwith %} {% endblock %} From b4ef800505de3305a428c8e455d9ce3be491d368 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 12:07:59 -0700 Subject: [PATCH 5/7] Hide start list item in readthrough if absent --- bookwyrm/templates/snippets/readthrough.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/templates/snippets/readthrough.html b/bookwyrm/templates/snippets/readthrough.html index cebdc2cd6..d5e79b864 100644 --- a/bookwyrm/templates/snippets/readthrough.html +++ b/bookwyrm/templates/snippets/readthrough.html @@ -48,7 +48,9 @@ {% endif %} {% endif %} + {% if readthrough.start_date %}
  • {{ readthrough.start_date | localtime | naturalday }}: {% trans "started" %}
  • + {% endif %}
    From 485d20696be089782b5c85f0e19c0d4b89d85ffd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 12:50:35 -0700 Subject: [PATCH 6/7] Fixes loading inventaire data by language code --- bookwyrm/connectors/abstract_connector.py | 4 ++++ bookwyrm/connectors/inventaire.py | 7 ++++++- .../connectors/test_inventaire_connector.py | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 767188232..db80677f3 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -217,6 +217,10 @@ def dict_from_mappings(data, mappings): the subclass""" result = {} for mapping in mappings: + # sometimes there are multiple mappings for one field, don't + # overwrite earlier writes in that case + if mapping.local_field in result and result[mapping.local_field]: + continue result[mapping.local_field] = mapping.get_value(data) return result diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index dc27f2c02..c13ef7f8a 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -21,6 +21,7 @@ class Connector(AbstractConnector): ] self.book_mappings = [ Mapping("title", remote_field="wdt:P1476", formatter=get_first), + Mapping("title", remote_field="labels", formatter=get_language_code), Mapping("subtitle", remote_field="wdt:P1680", formatter=get_first), Mapping("inventaireId", remote_field="uri"), Mapping( @@ -211,4 +212,8 @@ class Connector(AbstractConnector): def get_language_code(options, code="en"): """when there are a bunch of translation but we need a single field""" - return options.get(code) + result = options.get(code) + if result: + return result + values = list(options.values()) + return values[0] if values else None diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index 4058b0670..a32fa72be 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -5,7 +5,7 @@ from django.test import TestCase import responses from bookwyrm import models -from bookwyrm.connectors.inventaire import Connector +from bookwyrm.connectors.inventaire import Connector, get_language_code class Inventaire(TestCase): @@ -156,3 +156,18 @@ class Inventaire(TestCase): formatted.cover, "https://covers.inventaire.io/img/entities/12345", ) + + def test_get_language_code(self): + """ get english or whatever is in reach """ + options = { + "de": "bip", + "en": "hi", + "fr": "there", + } + self.assertEqual(get_language_code(options), "hi") + + options = { + "fr": "there", + } + self.assertEqual(get_language_code(options), "there") + self.assertIsNone(get_language_code({})) From 122e0cbd6d816cbb6f23c9d741a5d7d848b878a1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 12:52:20 -0700 Subject: [PATCH 7/7] Python formatting --- bookwyrm/tests/connectors/test_inventaire_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index a32fa72be..71e407e95 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -158,7 +158,7 @@ class Inventaire(TestCase): ) def test_get_language_code(self): - """ get english or whatever is in reach """ + """get english or whatever is in reach""" options = { "de": "bip", "en": "hi",