Separate ratings out from reviews on book page

This commit is contained in:
Mouse Reeve 2020-09-30 16:00:41 -07:00
parent 5c7f44dc2d
commit 0ab07c41ef
3 changed files with 33 additions and 18 deletions

View file

@ -1,5 +1,6 @@
{% extends 'layout.html' %}
{% load fr_display %}
{% load humanize %}
{% block content %}
<div class="block">
@ -89,12 +90,36 @@
</div>
{% endif %}
<div>
<div class="block">
{% for review in reviews %}
<div class="block">
{% include 'snippets/status.html' with status=review hide_book=True depth=1 %}
</div>
{% endfor %}
<div class="block columns">
{% for rating in ratings %}
<div class="column">
<div class="media">
<div class="media-left">{% include 'snippets/avatar.html' %}</div>
<div class="media-content">
<div>
{% include 'snippets/username.html' %}
</div>
<div class="field is-grouped mb-0">
<div>rated it</div>
{% include 'snippets/stars.html' with rating=rating.rating %}
</div>
<div>
<a href="{{ rating.remote_id }}">{{ rating.published_date | naturaltime }}</a>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -67,8 +67,6 @@ urlpatterns = [
# books
re_path(r'%s(.json)?/?$' % book_path, views.book_page),
re_path(r'%s/(?P<tab>friends|local|federated)?$' % \
book_path, views.book_page),
re_path(r'%s/edit/?$' % book_path, views.edit_book_page),
re_path(r'^editions/(?P<work_id>\d+)/?$', views.editions_page),

View file

@ -417,7 +417,7 @@ def edit_profile_page(request):
return TemplateResponse(request, 'edit_user.html', data)
def book_page(request, book_id, tab='friends'):
def book_page(request, book_id):
''' info about a book '''
book = models.Book.objects.select_subclasses().get(id=book_id)
if is_api_request(request):
@ -432,23 +432,15 @@ def book_page(request, book_id, tab='friends'):
if not work:
return HttpResponseNotFound()
book_reviews = models.Review.objects.filter(book__in=work.edition_set.all())
reviews = models.Review.objects.filter(
book__in=work.edition_set.all(),
).order_by('-published_date')
user_tags = []
if request.user.is_authenticated:
user_reviews = book_reviews.filter(
user=request.user,
).all()
reviews = get_activity_feed(request.user, tab, model=book_reviews)
user_tags = models.Tag.objects.filter(
book=book, user=request.user
).values_list('identifier', flat=True)
else:
tab = 'public'
reviews = book_reviews.filter(privacy='public')
user_reviews = []
user_tags = []
rating = reviews.aggregate(Avg('rating'))
tags = models.Tag.objects.filter(
@ -459,8 +451,8 @@ def book_page(request, book_id, tab='friends'):
data = {
'book': book,
'user_reviews': user_reviews,
'reviews': reviews.distinct(),
'reviews': reviews.filter(content__isnull=False),
'ratings': reviews.filter(content__isnull=True),
'rating': rating['rating__avg'],
'tags': tags,
'user_tags': user_tags,