forked from mirrors/bookwyrm
Use recent reviews instead of most reviewed books
This commit is contained in:
parent
8e923d6333
commit
0247f89c0b
3 changed files with 27 additions and 12 deletions
|
@ -1,8 +1,9 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% if book %}
|
||||
<div class="columns">
|
||||
<div class="column is-narrow">
|
||||
{% include 'snippets/book_cover.html' with book=book size="large" %}
|
||||
{% include 'snippets/stars.html' with rating=book.review__rating__avg %}
|
||||
{% include 'snippets/stars.html' with rating=ratings|dict_key:book.id %}
|
||||
</div>
|
||||
<div class="column">
|
||||
<h3 class="title is-5"><a href="/book/{{ book.id }}">{{ book.title }}</a></h3>
|
||||
|
@ -12,3 +13,4 @@
|
|||
<blockquote class="content">{{ book|book_description|to_markdown|safe|truncatewords_html:50 }}</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% if book %}
|
||||
{% include 'snippets/book_cover.html' with book=book %}
|
||||
{% include 'snippets/stars.html' with rating=book.review__rating__avg %}
|
||||
{% include 'snippets/stars.html' with rating=ratings|dict_key:book.id %}
|
||||
|
||||
<h3 class="title is-6"><a href="/book/{{ book.id }}">{{ book.title }}</a></h3>
|
||||
{% if book.authors %}
|
||||
<p class="subtitle is-6">by {% include 'snippets/authors.html' with book=book %}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
|
|
@ -4,7 +4,7 @@ import re
|
|||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Avg, Count, Q
|
||||
from django.db.models import Avg, F, Q, Max
|
||||
from django.db.models.functions import Greatest
|
||||
from django.http import HttpResponseNotFound, JsonResponse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
@ -64,11 +64,12 @@ def not_found_page(request, _):
|
|||
request, 'notfound.html', {'title': 'Not found'}, status=404)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_GET
|
||||
def home(request):
|
||||
''' this is the same as the feed on the home tab '''
|
||||
if request.user.is_authenticated:
|
||||
return home_tab(request, 'home')
|
||||
return discover_page(request)
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -134,19 +135,28 @@ def get_suggested_books(user, max_books=5):
|
|||
@require_GET
|
||||
def discover_page(request):
|
||||
''' tiled book activity page '''
|
||||
books = models.Edition.objects.exclude(
|
||||
books = models.Edition.objects.filter(
|
||||
review__published_date__isnull=False,
|
||||
review__user__local=True
|
||||
).exclude(
|
||||
cover__exact=''
|
||||
).annotate(
|
||||
Count('review')
|
||||
).annotate(
|
||||
Avg('review__rating')
|
||||
).order_by('-review__count')
|
||||
Max('review__published_date')
|
||||
).order_by('-review__published_date__max')[:6]
|
||||
|
||||
ratings = {}
|
||||
for book in books:
|
||||
reviews = models.Review.objects.filter(
|
||||
book__in=book.parent_work.editions.all()
|
||||
)
|
||||
reviews = get_activity_feed(
|
||||
request.user, 'federated', model=reviews)
|
||||
ratings[book.id] = reviews.aggregate(Avg('rating'))['rating__avg']
|
||||
data = {
|
||||
'title': 'Discover',
|
||||
'login_form': forms.LoginForm(),
|
||||
'register_form': forms.RegisterForm(),
|
||||
'books': books
|
||||
'books': list(set(books)),
|
||||
'ratings': ratings
|
||||
}
|
||||
return TemplateResponse(request, 'discover.html', data)
|
||||
|
||||
|
|
Loading…
Reference in a new issue