diff --git a/fedireads/connectors/openlibrary.py b/fedireads/connectors/openlibrary.py index 95819f7d..e99cf99d 100644 --- a/fedireads/connectors/openlibrary.py +++ b/fedireads/connectors/openlibrary.py @@ -49,9 +49,9 @@ class Connector(AbstractConnector): annotated with work data. ''' try: - book = models.Book.objects.select_subclasses().get( + book = models.Book.objects.select_subclasses().filter( openlibrary_key=olkey - ) + ).first() return book except ObjectDoesNotExist: pass @@ -119,7 +119,7 @@ class Connector(AbstractConnector): author_id = author_blob['key'] author_id = author_id.split('/')[-1] book.authors.add(self.get_or_create_author(author_id)) - if not data.get('authors'): + if not data.get('authors') and book.parent_work.authors.count(): book.authors.set(book.parent_work.authors.all()) @@ -166,7 +166,7 @@ class Connector(AbstractConnector): try: models.Edition.objects.get(openlibrary_key=olkey) - except ObjectDoesNotExist: + except models.Edition.DoesNotExist: book = models.Edition.objects.create(openlibrary_key=olkey) self.update_from_data(book, data) @@ -177,7 +177,7 @@ class Connector(AbstractConnector): raise ValueError('Invalid OpenLibrary author ID') try: return models.Author.objects.get(openlibrary_key=olkey) - except ObjectDoesNotExist: + except models.Author.DoesNotExist: pass response = requests.get('%s/authors/%s.json' % (self.url, olkey)) diff --git a/fedireads/static/format.css b/fedireads/static/format.css index dd6d3a59..e402013d 100644 --- a/fedireads/static/format.css +++ b/fedireads/static/format.css @@ -546,15 +546,17 @@ dd { } .tag { - border: 1px solid black; display: inline-block; padding: 0.2em; border-radius: 0.2em; - background-color: #F3FFBD; + background-color: #EEE; } .tag form { display: inline; } +.tag a { + text-decoration: none; +} blockquote { white-space: pre-line; diff --git a/fedireads/templates/book.html b/fedireads/templates/book.html index a35f30f5..e7197e46 100644 --- a/fedireads/templates/book.html +++ b/fedireads/templates/book.html @@ -48,14 +48,8 @@

{{ book.parent_work.edition_set.count }} editions

{% endif %} -
- {% for tag in tags %} - {% include 'snippets/tag.html' with tag=tag user=request.user user_tags=user_tag_names %} - {% endfor %} -
- + {% if request.user.is_authenticated %}
- {% if request.user.is_authenticated %}

Leave a review

{% csrf_token %} @@ -64,8 +58,24 @@ {{ review_form.as_p }}
- {% endif %}
+ +
+

Tags

+
+ {% csrf_token %} + + + +
+
+
+ {% for tag in tags %} + {% include 'snippets/tag.html' with book=book tag=tag user_tags=user_tags %} + {% endfor %} +
+ + {% endif %} diff --git a/fedireads/templates/books.html b/fedireads/templates/books.html index 4b42b460..af522100 100644 --- a/fedireads/templates/books.html +++ b/fedireads/templates/books.html @@ -3,9 +3,9 @@ {% block content %}

Recently Added Books

-
+
{% for book in books %} -
+
{% include 'snippets/book_cover.html' with book=book %} diff --git a/fedireads/templates/tag.html b/fedireads/templates/tag.html index 8c18f400..3f77941c 100644 --- a/fedireads/templates/tag.html +++ b/fedireads/templates/tag.html @@ -1,12 +1,16 @@ {% extends 'layout.html' %} {% load fr_display %} {% block content %} -
-
-

Books tagged "{{ tag.name }}"

+
+

Books tagged "{{ tag.name }}"

+
{% for book in books.all %} -
- {% include 'snippets/book.html' with book=book size=large %} +
+ + {% include 'snippets/book_cover.html' with book=book %} + + {% include 'snippets/rate_action.html' with user=request.user book=book %} + {% include 'snippets/shelve_button.html' with book=book %}
{% endfor %}
diff --git a/fedireads/views.py b/fedireads/views.py index e7a50650..bc5efb9a 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -354,6 +354,8 @@ def book_page(request, book_identifier, tab='friends'): book = book.default_edition work = book.parent_work + if not work: + return HttpResponseNotFound() book_reviews = models.Review.objects.filter(book__in=work.edition_set.all()) @@ -375,18 +377,13 @@ def book_page(request, book_identifier, tab='friends'): user_tags = models.Tag.objects.filter( book=book, user=request.user - ).all() - user_tag_names = user_tags.values_list('identifier', flat=True) - - user_rating = user_reviews.aggregate(Avg('rating')), + ).values_list('identifier', flat=True) else: tab = 'public' reviews = book_reviews.filter(privacy='public') shelf = None user_reviews = [] - user_rating = None user_tags = [] - user_tag_names = [] rating = reviews.aggregate(Avg('rating')) tags = models.Tag.objects.filter( @@ -399,12 +396,10 @@ def book_page(request, book_identifier, tab='friends'): 'book': book, 'shelf': shelf, 'user_reviews': user_reviews, - 'user_rating': user_rating, 'reviews': reviews.distinct(), 'rating': rating['rating__avg'], 'tags': tags, 'user_tags': user_tags, - 'user_tag_names': user_tag_names, 'review_form': forms.ReviewForm(), 'tag_form': forms.TagForm(), 'feed_tabs': [