diff --git a/bookwyrm/templates/about/about.html b/bookwyrm/templates/about/about.html index e297a9ed0..ae4914c2f 100644 --- a/bookwyrm/templates/about/about.html +++ b/bookwyrm/templates/about/about.html @@ -22,54 +22,60 @@
{% if top_rated %} + {% with book=top_rated.default_edition rating=top_rated.rating %}
- {% blocktrans trimmed with title=top_rated|book_title book_path=top_rated.local_path site_name=site.name rating=top_rated.rating|floatformat:1 %} + {% blocktrans trimmed with title=book|book_title book_path=book.local_path site_name=site.name rating=rating|floatformat:1 %} {{ title }} is {{ site_name }}'s most beloved book, with an average rating of {{ rating }} out of 5. {% endblocktrans %}
+ {% endwith %} {% endif %} {% if wanted %} + {% with book=wanted.default_edition %}
- {% blocktrans trimmed with title=wanted|book_title book_path=wanted.local_path site_name=site.name %} + {% blocktrans trimmed with title=book|book_title book_path=book.local_path site_name=site.name %} More {{ site_name }} users want to read {{ title }} than any other book. {% endblocktrans %}
+ {% endwith %} {% endif %} {% if controversial %} + {% with book=controversial.default_edition %}
- {% blocktrans trimmed with title=controversial|book_title book_path=controversial.local_path site_name=site.name %} + {% blocktrans trimmed with title=book|book_title book_path=book.local_path site_name=site.name %} {{ title }} has the most divisive ratings of any book on {{ site_name }}. {% endblocktrans %}
+ {% endwith %} {% endif %}
diff --git a/bookwyrm/views/landing/about.py b/bookwyrm/views/landing/about.py index f1d851df3..7d53a3a12 100644 --- a/bookwyrm/views/landing/about.py +++ b/bookwyrm/views/landing/about.py @@ -24,37 +24,33 @@ def about(request): "version": settings.VERSION, } - books = models.Edition.objects.exclude(cover__exact="") - - total_ratings = models.Review.objects.filter( - user__local=True, deleted=False - ).count() + total_ratings = models.Review.objects.filter(local=True, deleted=False).count() data["top_rated"] = ( - books.annotate( + models.Work.objects.annotate( rating=Avg( - "review__rating", - filter=Q(review__user__local=True, review__deleted=False), + "editions__review__rating", + filter=Q(editions__review__local=True, editions__review__deleted=False), ), rating_count=Count( - "review__rating", - filter=Q(review__user__local=True, review__deleted=False), + "editions__review", + filter=Q(editions__review__local=True, editions__review__deleted=False), ), ) .annotate(weighted=F("rating") * F("rating_count") / total_ratings) - .filter(weighted__gt=0) + .filter(rating__gt=4, weighted__gt=0) .order_by("-weighted") .first() ) data["controversial"] = ( - books.annotate( + models.Work.objects.annotate( deviation=StdDev( - "review__rating", - filter=Q(review__user__local=True, review__deleted=False), + "editions__review__rating", + filter=Q(editions__review__local=True, editions__review__deleted=False), ), rating_count=Count( - "review__rating", - filter=Q(review__user__local=True, review__deleted=False), + "editions__review", + filter=Q(editions__review__local=True, editions__review__deleted=False), ), ) .annotate(weighted=F("deviation") * F("rating_count") / total_ratings) @@ -64,8 +60,10 @@ def about(request): ) data["wanted"] = ( - books.annotate( - shelf_count=Count("shelves", filter=Q(shelves__identifier="to-read")) + models.Work.objects.annotate( + shelf_count=Count( + "editions__shelves", filter=Q(editions__shelves__identifier="to-read") + ) ) .order_by("-shelf_count") .first()