forked from mirrors/bookwyrm
Simplifies query for landing page books
This commit is contained in:
parent
b116df723f
commit
c28d077cb4
2 changed files with 18 additions and 22 deletions
|
@ -10,18 +10,18 @@
|
|||
<div class="tile is-vertical is-6">
|
||||
<div class="tile is-parent">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/large-book.html' with book=books.has_description.0 %}
|
||||
{% include 'landing/large-book.html' with book=books.0 %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<div class="tile is-parent is-6">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/small-book.html' with book=books.no_description.0 %}
|
||||
{% include 'landing/small-book.html' with book=books.1 %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tile is-parent is-6">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/small-book.html' with book=books.no_description.1 %}
|
||||
{% include 'landing/small-book.html' with book=books.2 %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -30,18 +30,18 @@
|
|||
<div class="tile">
|
||||
<div class="tile is-parent is-6">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/small-book.html' with book=books.no_description.2 %}
|
||||
{% include 'landing/small-book.html' with book=books.3 %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tile is-parent is-6">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/small-book.html' with book=books.no_description.3 %}
|
||||
{% include 'landing/small-book.html' with book=books.4 %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tile is-parent">
|
||||
<div class="tile is-child box has-background-white-ter">
|
||||
{% include 'landing/large-book.html' with book=books.has_description.1 %}
|
||||
{% include 'landing/large-book.html' with book=books.5 %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import re
|
||||
from requests import HTTPError
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db.models import Max, Q
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
|
||||
from bookwyrm import activitypub, models
|
||||
|
@ -165,20 +165,16 @@ def is_blocked(viewer, user):
|
|||
def get_landing_books():
|
||||
"""list of books for the landing page"""
|
||||
|
||||
options = (
|
||||
models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__deleted=False,
|
||||
review__user__local=True,
|
||||
review__privacy__in=["public", "unlisted"],
|
||||
return list(
|
||||
set(
|
||||
models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__deleted=False,
|
||||
review__user__local=True,
|
||||
review__privacy__in=["public", "unlisted"],
|
||||
)
|
||||
.exclude(cover__exact="")
|
||||
.distinct()
|
||||
.order_by("-review__published_date")[:6]
|
||||
)
|
||||
.exclude(cover__exact="")
|
||||
.annotate(Max("review__published_date"))
|
||||
.order_by("-review__published_date__max")
|
||||
)
|
||||
|
||||
has_description = options.exclude(description=None).exclude(description="")
|
||||
return {
|
||||
"has_description": has_description[:2],
|
||||
"no_description": options.exclude(id__in=has_description)[:4],
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue