Python formatting

This commit is contained in:
Mouse Reeve 2022-01-06 09:48:36 -08:00
parent 461bfd0ce7
commit b8c72d75e5

View file

@ -29,24 +29,50 @@ def about(request):
books = models.Edition.objects.exclude(cover__exact="") 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(
data["top_rated"] = books.annotate( user__local=True, deleted=False
rating=Avg("review__rating", filter=Q(review__user__local=True, review__deleted=False)), ).count()
rating_count=Count("review__rating", filter=Q(review__user__local=True, review__deleted=False)), data["top_rated"] = (
).annotate( books.annotate(
weighted=F("rating") * F("rating_count") / total_ratings rating=Avg(
).filter(weighted__gt=0).order_by("-weighted").first() "review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
rating_count=Count(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
)
.annotate(weighted=F("rating") * F("rating_count") / total_ratings)
.filter(weighted__gt=0)
.order_by("-weighted")
.first()
)
data["controversial"] = books.annotate( data["controversial"] = (
deviation=StdDev("review__rating", filter=Q(review__user__local=True, review__deleted=False)), books.annotate(
rating_count=Count("review__rating", filter=Q(review__user__local=True, review__deleted=False)), deviation=StdDev(
).annotate( "review__rating",
weighted=F("deviation") * F("rating_count") / total_ratings filter=Q(review__user__local=True, review__deleted=False),
).filter(weighted__gt=0).order_by("-weighted").first() ),
rating_count=Count(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
)
.annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
.filter(weighted__gt=0)
.order_by("-weighted")
.first()
)
data["wanted"] = books.annotate( data["wanted"] = (
books.annotate(
shelf_count=Count("shelves", filter=Q(shelves__identifier="to-read")) shelf_count=Count("shelves", filter=Q(shelves__identifier="to-read"))
).order_by("-shelf_count").first() )
.order_by("-shelf_count")
.first()
)
return TemplateResponse(request, "about/about.html", data) return TemplateResponse(request, "about/about.html", data)