-
{{ author.data.name }}
- {% if author.data.bio %} -{{ author.data.bio | author_bio }} +{{ author.name }}
+ {% if author.bio %} +{{ author.bio | author_bio }}{% endif %} {% for book in books %} diff --git a/fedireads/templates/book.html b/fedireads/templates/book.html index 60c679217..73e3c12d2 100644 --- a/fedireads/templates/book.html +++ b/fedireads/templates/book.html @@ -3,7 +3,7 @@ {% block content %}-+
{{ book.data.title }}and You
{{ book.title }}and You{% if shelf %}On shelf
{% include 'snippets/shelve-button.html' with book=book pulldown=True %} @@ -27,13 +27,15 @@{{ shelf.name }}{% endif %}-
{{ book.data.title }}by ++ {% if book.parent_work %}
{{ book.title }}by {% include 'snippets/authors.html' with book=book %}Edition of {{ book.parent_work.title }}
{% endif %}+ {% include 'snippets/book_cover.html' with book=book size=large %}{{ active_tab }} rating: {{ rating | stars }}
{% if description %} -{{ book.data.description | description }}+{{ book.description | description }}{% endif %}diff --git a/fedireads/templates/book_results.html b/fedireads/templates/book_results.html index be2ee35b9..bb7fa735d 100644 --- a/fedireads/templates/book_results.html +++ b/fedireads/templates/book_results.html @@ -5,7 +5,7 @@diff --git a/fedireads/templates/snippets/authors.html b/fedireads/templates/snippets/authors.html index bc392089d..1d619153b 100644 --- a/fedireads/templates/snippets/authors.html +++ b/fedireads/templates/snippets/authors.html @@ -1 +1 @@ -by {{ book.authors.first.data.name }} +{{ book.authors.first.name }} diff --git a/fedireads/templates/snippets/book.html b/fedireads/templates/snippets/book.html index d25b36c82..2b28e76df 100644 --- a/fedireads/templates/snippets/book.html +++ b/fedireads/templates/snippets/book.html @@ -1,10 +1,10 @@ {% load fr_display %} {% include 'snippets/book_cover.html' with book=book %}Search results
{% for result in results %}- {{ result.title }} by {{ result.author }} ({{ result.year }}) + {{ result.title }} by {{ result.author }} ({{ result.year }}){% endfor %}- {{ book.data.title }} + {{ book.title }}
- {% include 'snippets/authors.html' with book=book %} + by {% include 'snippets/authors.html' with book=book %}
{% if rating %} @@ -12,7 +12,7 @@ {% endif %} {% if description %} -{{ book.data.description | description }}+{{ book.description | description }}{% endif %} {% include 'snippets/shelve-button.html' with book=book pulldown=shelf_pulldown %} diff --git a/fedireads/templates/snippets/shelf.html b/fedireads/templates/snippets/shelf.html index 651a4808e..18794d0e8 100644 --- a/fedireads/templates/snippets/shelf.html +++ b/fedireads/templates/snippets/shelf.html @@ -33,19 +33,19 @@ {% include 'snippets/book_cover.html' with book=book %}- {{ book.data.title }} + {{ book.title }} {{ book.authors.first.data.name }} - {{ book.data.first_publish_date }} + {{ book.first_publish_date }} {{ book.added_date | naturalday }} - OpenLibrary + OpenLibrary {% if ratings %}diff --git a/fedireads/templates/snippets/status.html b/fedireads/templates/snippets/status.html index 04942d1f4..fa58fee4d 100644 --- a/fedireads/templates/snippets/status.html +++ b/fedireads/templates/snippets/status.html @@ -1,7 +1,7 @@ {% load fr_display %} {% if activity.status_type == 'Review' %} - {% include 'snippets/status_banner.html' with content="reviewed "|add:activity.book.data.title|add:"" %} + {% include 'snippets/status_banner.html' with content="reviewed "|add:activity.book.title|add:"" %}{% include 'snippets/book.html' with book=activity.book size=large %} diff --git a/fedireads/templatetags/fr_display.py b/fedireads/templatetags/fr_display.py index 41d5591d9..2f5b5ac60 100644 --- a/fedireads/templatetags/fr_display.py +++ b/fedireads/templatetags/fr_display.py @@ -11,6 +11,7 @@ def dict_key(d, k): '''Returns the given key from a dictionary.''' return d.get(k) or 0 + @register.filter(name='stars') def stars(number): ''' turn integers into stars ''' @@ -20,16 +21,19 @@ def stars(number): number = 0 return ('★' * number) + '☆' * (5 - number) + @register.filter(name='description') def description_format(description): ''' handle the various OL description formats ''' - if isinstance(description, dict) and 'value' in description: - description = description['value'] + if not description: + return '' + if '----------' in description: description = description.split('----------')[0] return description.strip() + @register.filter(name='author_bio') def bio_format(bio): ''' clean up OL author bios ''' diff --git a/fedireads/utils/models.py b/fedireads/utils/models.py index dfb491e2d..93821ca19 100644 --- a/fedireads/utils/models.py +++ b/fedireads/utils/models.py @@ -1,3 +1,4 @@ +''' base model with default fields ''' from django.db import models from fedireads.settings import DOMAIN diff --git a/fedireads/view_actions.py b/fedireads/view_actions.py index e016c3a13..5595cb020 100644 --- a/fedireads/view_actions.py +++ b/fedireads/view_actions.py @@ -5,7 +5,7 @@ from django.shortcuts import redirect from django.template.response import TemplateResponse import re -from fedireads import forms, models, openlibrary, outgoing +from fedireads import forms, models, books_manager, outgoing from fedireads.views import get_user_from_username @@ -150,8 +150,8 @@ def search(request): results = [outgoing.handle_account_search(query)] template = 'user_results.html' else: - # just send the question over to openlibrary for book search - results = openlibrary.book_search(query) + # just send the question over to book search + results = books_manager.search(query) template = 'book_results.html' return TemplateResponse(request, template, {'results': results}) diff --git a/fedireads/views.py b/fedireads/views.py index 3dab26d76..b8f94bd7e 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponseNotFound from django.shortcuts import redirect from django.template.response import TemplateResponse -from fedireads import forms, models, openlibrary, incoming +from fedireads import forms, models, books_manager, incoming from fedireads.settings import DOMAIN @@ -188,28 +188,35 @@ def edit_profile_page(request, username): @login_required def book_page(request, book_identifier, tab='friends'): ''' info about a book ''' - book = openlibrary.get_or_create_book(book_identifier) + book = books_manager.get_or_create_book(book_identifier) - user_reviews = models.Review.objects.filter(user=request.user, book=book).all() + if isinstance(book, models.Work): + book_reviews = models.Review.objects.filter( + Q(book=book) | Q(book__parent_work=book), + ) + else: + book_reviews = models.Review.objects.filter(book=book) + + user_reviews = book_reviews.filter( + user=request.user, + ).all() if tab == 'friends': - reviews = models.Review.objects.filter( + reviews = book_reviews.filter( Q(user__followers=request.user, privacy='public') | \ + Q(user=request.user) | \ Q(mention_users=request.user), - book=book, ) elif tab == 'local': - reviews = models.Review.objects.filter( + reviews = book_reviews.filter( Q(privacy='public') | \ Q(mention_users=request.user), user__local=True, - book=book, ) else: - reviews = models.Review.objects.filter( + reviews = book_reviews.filter( Q(privacy='public') | \ Q(mention_users=request.user), - book=book, ) try: @@ -251,7 +258,7 @@ def book_page(request, book_identifier, tab='friends'): def author_page(request, author_identifier): ''' landing page for an author ''' try: - author = models.Author.objects.get(openlibrary_key=author_identifier) + author = models.Author.objects.get(books_manager_key=author_identifier) except ValueError: return HttpResponseNotFound() diff --git a/init_db.py b/init_db.py index c112b5a78..eb5e2ed89 100644 --- a/init_db.py +++ b/init_db.py @@ -1,5 +1,5 @@ from fedireads.models import User -from fedireads.openlibrary import get_or_create_book +from fedireads.books_manager import get_or_create_book User.objects.create_user('mouse', 'mouse.reeve@gmail.com', 'password123') User.objects.create_user('rat', 'rat@rat.com', 'ratword')