Simplifies query for landing page books
This commit is contained in:
parent
b116df723f
commit
c28d077cb4
|
@ -10,18 +10,18 @@
|
||||||
<div class="tile is-vertical is-6">
|
<div class="tile is-vertical is-6">
|
||||||
<div class="tile is-parent">
|
<div class="tile is-parent">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
</div>
|
||||||
<div class="tile">
|
<div class="tile">
|
||||||
<div class="tile is-parent is-6">
|
<div class="tile is-parent is-6">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
</div>
|
||||||
<div class="tile is-parent is-6">
|
<div class="tile is-parent is-6">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,18 +30,18 @@
|
||||||
<div class="tile">
|
<div class="tile">
|
||||||
<div class="tile is-parent is-6">
|
<div class="tile is-parent is-6">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
</div>
|
||||||
<div class="tile is-parent is-6">
|
<div class="tile is-parent is-6">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<div class="tile is-parent">
|
<div class="tile is-parent">
|
||||||
<div class="tile is-child box has-background-white-ter">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import re
|
import re
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from django.core.exceptions import FieldError
|
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 django.http import Http404
|
||||||
|
|
||||||
from bookwyrm import activitypub, models
|
from bookwyrm import activitypub, models
|
||||||
|
@ -165,20 +165,16 @@ def is_blocked(viewer, user):
|
||||||
def get_landing_books():
|
def get_landing_books():
|
||||||
"""list of books for the landing page"""
|
"""list of books for the landing page"""
|
||||||
|
|
||||||
options = (
|
return list(
|
||||||
models.Edition.objects.filter(
|
set(
|
||||||
review__published_date__isnull=False,
|
models.Edition.objects.filter(
|
||||||
review__deleted=False,
|
review__published_date__isnull=False,
|
||||||
review__user__local=True,
|
review__deleted=False,
|
||||||
review__privacy__in=["public", "unlisted"],
|
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 New Issue