Updates queries
This commit is contained in:
parent
392dbfce01
commit
bb4b724b1a
|
@ -22,54 +22,60 @@
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
{% if top_rated %}
|
{% if top_rated %}
|
||||||
|
{% with book=top_rated.default_edition rating=top_rated.rating %}
|
||||||
<div class="column is-one-third is-flex">
|
<div class="column is-one-third is-flex">
|
||||||
<div class="media notification">
|
<div class="media notification">
|
||||||
<div class="media-left">
|
<div class="media-left">
|
||||||
<a href="{{ top_rated.local_path }}">
|
<a href="{{ book.local_path }}">
|
||||||
{% include 'snippets/book_cover.html' with book=top_rated cover_class='is-h-m' size='medium' aria='show' %}
|
{% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content">
|
<div class="media-content">
|
||||||
{% 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 %}
|
||||||
<a href="{{ book_path }}"><em>{{ title }}</em></a> is {{ site_name }}'s most beloved book, with an average rating of {{ rating }} out of 5.
|
<a href="{{ book_path }}"><em>{{ title }}</em></a> is {{ site_name }}'s most beloved book, with an average rating of {{ rating }} out of 5.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if wanted %}
|
{% if wanted %}
|
||||||
|
{% with book=wanted.default_edition %}
|
||||||
<div class="column is-one-third is-flex">
|
<div class="column is-one-third is-flex">
|
||||||
<div class="media notification">
|
<div class="media notification">
|
||||||
<div class="media-left">
|
<div class="media-left">
|
||||||
<a href="{{ wanted.local_path }}">
|
<a href="{{ book.local_path }}">
|
||||||
{% include 'snippets/book_cover.html' with book=wanted cover_class='is-h-m' size='medium' aria='show' %}
|
{% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content">
|
<div class="media-content">
|
||||||
{% 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 <a href="{{ book_path }}"><em>{{ title }}</em></a> than any other book.
|
More {{ site_name }} users want to read <a href="{{ book_path }}"><em>{{ title }}</em></a> than any other book.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if controversial %}
|
{% if controversial %}
|
||||||
|
{% with book=controversial.default_edition %}
|
||||||
<div class="column is-one-third is-flex">
|
<div class="column is-one-third is-flex">
|
||||||
<div class="media notification">
|
<div class="media notification">
|
||||||
<div class="media-left">
|
<div class="media-left">
|
||||||
<a href="{{ controversial.local_path }}">
|
<a href="{{ book.local_path }}">
|
||||||
{% include 'snippets/book_cover.html' with book=controversial cover_class='is-h-m' size='medium' aria='show' %}
|
{% include 'snippets/book_cover.html' with book=book cover_class='is-h-m' size='medium' aria='show' %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content">
|
<div class="media-content">
|
||||||
{% 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 %}
|
||||||
<a href="{{ book_path }}"><em>{{ title }}</em></a> has the most divisive ratings of any book on {{ site_name }}.
|
<a href="{{ book_path }}"><em>{{ title }}</em></a> has the most divisive ratings of any book on {{ site_name }}.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -24,37 +24,33 @@ def about(request):
|
||||||
"version": settings.VERSION,
|
"version": settings.VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
books = models.Edition.objects.exclude(cover__exact="")
|
total_ratings = models.Review.objects.filter(local=True, deleted=False).count()
|
||||||
|
|
||||||
total_ratings = models.Review.objects.filter(
|
|
||||||
user__local=True, deleted=False
|
|
||||||
).count()
|
|
||||||
data["top_rated"] = (
|
data["top_rated"] = (
|
||||||
books.annotate(
|
models.Work.objects.annotate(
|
||||||
rating=Avg(
|
rating=Avg(
|
||||||
"review__rating",
|
"editions__review__rating",
|
||||||
filter=Q(review__user__local=True, review__deleted=False),
|
filter=Q(editions__review__local=True, editions__review__deleted=False),
|
||||||
),
|
),
|
||||||
rating_count=Count(
|
rating_count=Count(
|
||||||
"review__rating",
|
"editions__review",
|
||||||
filter=Q(review__user__local=True, review__deleted=False),
|
filter=Q(editions__review__local=True, editions__review__deleted=False),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.annotate(weighted=F("rating") * F("rating_count") / total_ratings)
|
.annotate(weighted=F("rating") * F("rating_count") / total_ratings)
|
||||||
.filter(weighted__gt=0)
|
.filter(rating__gt=4, weighted__gt=0)
|
||||||
.order_by("-weighted")
|
.order_by("-weighted")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
data["controversial"] = (
|
data["controversial"] = (
|
||||||
books.annotate(
|
models.Work.objects.annotate(
|
||||||
deviation=StdDev(
|
deviation=StdDev(
|
||||||
"review__rating",
|
"editions__review__rating",
|
||||||
filter=Q(review__user__local=True, review__deleted=False),
|
filter=Q(editions__review__local=True, editions__review__deleted=False),
|
||||||
),
|
),
|
||||||
rating_count=Count(
|
rating_count=Count(
|
||||||
"review__rating",
|
"editions__review",
|
||||||
filter=Q(review__user__local=True, review__deleted=False),
|
filter=Q(editions__review__local=True, editions__review__deleted=False),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
|
.annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
|
||||||
|
@ -64,8 +60,10 @@ def about(request):
|
||||||
)
|
)
|
||||||
|
|
||||||
data["wanted"] = (
|
data["wanted"] = (
|
||||||
books.annotate(
|
models.Work.objects.annotate(
|
||||||
shelf_count=Count("shelves", filter=Q(shelves__identifier="to-read"))
|
shelf_count=Count(
|
||||||
|
"editions__shelves", filter=Q(editions__shelves__identifier="to-read")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.order_by("-shelf_count")
|
.order_by("-shelf_count")
|
||||||
.first()
|
.first()
|
||||||
|
|
Loading…
Reference in New Issue