show featured collection on discover
This commit is contained in:
parent
dcc2d6ea41
commit
e38764caea
3 changed files with 50 additions and 1 deletions
|
@ -10,7 +10,8 @@ from loguru import logger
|
|||
|
||||
from catalog.models import *
|
||||
from common.models import BaseJob, JobManager
|
||||
from journal.models import Comment, ShelfMember, q_item_in_category
|
||||
from journal.models import Collection, Comment, ShelfMember, q_item_in_category
|
||||
from users.models import APIdentity
|
||||
|
||||
MAX_ITEMS_PER_PERIOD = 12
|
||||
MIN_MARKS = settings.MIN_MARKS_FOR_DISCOVER
|
||||
|
@ -123,6 +124,14 @@ class DiscoverGenerator(BaseJob):
|
|||
}
|
||||
)
|
||||
trends.sort(key=lambda x: x["history"][0]["accounts"], reverse=True)
|
||||
collection_ids = (
|
||||
Collection.objects.filter(visibility=0)
|
||||
.annotate(num=Count("interactions"))
|
||||
.filter(num__gte=MIN_MARKS)
|
||||
.order_by("-edited_time")
|
||||
.values_list("pk", flat=True)[:40]
|
||||
)
|
||||
cache.set(cache_key, gallery_list, timeout=None)
|
||||
cache.set("trends_links", trends, timeout=None)
|
||||
cache.set("featured_collections", collection_ids, timeout=None)
|
||||
logger.info(f"Discover data updated, trends: {len(trends)}.")
|
||||
|
|
|
@ -66,6 +66,35 @@
|
|||
</ul>
|
||||
</section>
|
||||
{% endfor %}
|
||||
<section class="entity-sort shelf"
|
||||
id="featured_collections"
|
||||
{% if not featured_collections %}style="display:none;"{% endif %}>
|
||||
<span class="action">
|
||||
<span>
|
||||
<a _="on click set el to the next
|
||||
<ul/>
|
||||
then call el.scrollBy({left:-el.offsetWidth, behavior:'smooth'})"><i class="fa-solid fa-circle-left"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
<a _="on click set el to the next
|
||||
<ul/>
|
||||
then call el.scrollBy({left:el.offsetWidth, behavior:'smooth'})"><i class="fa-solid fa-circle-right"></i></a>
|
||||
</span>
|
||||
</span>
|
||||
<h5>{% trans "Collections" %}</h5>
|
||||
<ul class="cards">
|
||||
{% for item in featured_collections %}
|
||||
<li class="card">
|
||||
<a href="{{ item.url }}" title="{{ item.title }}">
|
||||
<img src="{{ item.cover|thumb:'normal' }}"
|
||||
alt="{{ item.title }}"
|
||||
loading="lazy">
|
||||
<div class="card-title">{{ item.title }}</div>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="entity-sort-control">
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.views.decorators.http import require_http_methods
|
|||
|
||||
from common.utils import PageLinksGenerator, get_uuid_or_404, user_identity_required
|
||||
from journal.models import (
|
||||
Collection,
|
||||
Comment,
|
||||
Mark,
|
||||
Review,
|
||||
|
@ -21,6 +22,7 @@ from journal.models import (
|
|||
q_piece_in_home_feed_of_user,
|
||||
q_piece_visible_to_user,
|
||||
)
|
||||
from users.models.apidentity import APIdentity
|
||||
|
||||
from .forms import *
|
||||
from .models import *
|
||||
|
@ -291,6 +293,14 @@ def discover(request):
|
|||
tvshows_in_progress = []
|
||||
layout = []
|
||||
|
||||
collection_ids = cache.get("featured_collections", [])
|
||||
if collection_ids:
|
||||
i = rot * len(collection_ids) // 10
|
||||
collection_ids = collection_ids[i:] + collection_ids[:i]
|
||||
featured_collections = Collection.objects.filter(pk__in=collection_ids)
|
||||
else:
|
||||
featured_collections = []
|
||||
|
||||
return render(
|
||||
request,
|
||||
"discover.html",
|
||||
|
@ -300,6 +310,7 @@ def discover(request):
|
|||
"recent_podcast_episodes": recent_podcast_episodes,
|
||||
"books_in_progress": books_in_progress,
|
||||
"tvshows_in_progress": tvshows_in_progress,
|
||||
"featured_collections": featured_collections,
|
||||
"layout": layout,
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue