Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-11-15 13:47:32 -08:00
commit ab06180e41
4 changed files with 24 additions and 13 deletions

View file

@ -189,8 +189,10 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
if hasattr(activity, "name"):
activity.name = self.pure_name
activity.type = self.pure_type
books = [getattr(self, "book", None)] + list(self.mention_books.all())
if len(books) == 1 and books[0].preview_image:
book = getattr(self, "book", None)
books = [book] if book else []
books += list(self.mention_books.all())
if len(books) == 1 and getattr(books[0], "preview_image", None):
covers = [
activitypub.Document(
url=fields.get_absolute_url(books[0].preview_image),

View file

@ -46,8 +46,10 @@
{% include 'snippets/book_cover.html' with book=guess cover_class='is-h-s' size='small' %}
</a>
</div>
<div class="column">
{% include 'snippets/book_titleby.html' with book=guess %}
<div class="column content">
<p>
{% include 'snippets/book_titleby.html' with book=guess %}
</p>
<div class="content is-flex">
<form class="pr-2" name="approve-{{ item.id }}" method="POST" action="{% url 'import-approve' job.id item.id %}">
{% csrf_token %}

View file

@ -5,11 +5,9 @@
{% if book.authors.exists %}
{% blocktrans trimmed with path=book.local_path title=book|book_title %}
<a href="{{ path }}">{{ title }}</a> by
{% endblocktrans %}
{% include 'snippets/authors.html' with book=book limit=3 %}
{% endblocktrans %}&nbsp;{% include 'snippets/authors.html' with book=book limit=3 %}
{% else %}
<a href="{{ book.local_path }}">{{ book|book_title }}</a>
{% endif %}
{% endspaceless %}

View file

@ -1,6 +1,7 @@
""" non-interactive pages """
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.db.models import Q, Count
from django.http import Http404
from django.shortcuts import redirect
from django.template.response import TemplateResponse
@ -105,9 +106,8 @@ class Followers(View):
if is_api_request(request):
return ActivitypubResponse(user.to_followers_activity(**request.GET))
paginated = Paginator(
user.followers.order_by("-created_date").all(), PAGE_LENGTH
)
followers = annotate_if_follows(request.user, user.followers)
paginated = Paginator(followers.all(), PAGE_LENGTH)
data = {
"user": user,
"is_self": request.user.id == user.id,
@ -126,9 +126,8 @@ class Following(View):
if is_api_request(request):
return ActivitypubResponse(user.to_following_activity(**request.GET))
paginated = Paginator(
user.following.order_by("-created_date").all(), PAGE_LENGTH
)
following = annotate_if_follows(request.user, user.following)
paginated = Paginator(following.all(), PAGE_LENGTH)
data = {
"user": user,
"is_self": request.user.id == user.id,
@ -137,6 +136,16 @@ class Following(View):
return TemplateResponse(request, "user/relationships/following.html", data)
def annotate_if_follows(user, queryset):
"""Sort a list of users by if you follow them"""
if not user.is_authenticated:
return queryset.order_by("-created_date")
return queryset.annotate(
request_user_follows=Count("followers", filter=Q(followers=user))
).order_by("-request_user_follows", "-created_date")
class Groups(View):
"""list of user's groups view"""