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"): if hasattr(activity, "name"):
activity.name = self.pure_name activity.name = self.pure_name
activity.type = self.pure_type activity.type = self.pure_type
books = [getattr(self, "book", None)] + list(self.mention_books.all()) book = getattr(self, "book", None)
if len(books) == 1 and books[0].preview_image: books = [book] if book else []
books += list(self.mention_books.all())
if len(books) == 1 and getattr(books[0], "preview_image", None):
covers = [ covers = [
activitypub.Document( activitypub.Document(
url=fields.get_absolute_url(books[0].preview_image), 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' %} {% include 'snippets/book_cover.html' with book=guess cover_class='is-h-s' size='small' %}
</a> </a>
</div> </div>
<div class="column"> <div class="column content">
{% include 'snippets/book_titleby.html' with book=guess %} <p>
{% include 'snippets/book_titleby.html' with book=guess %}
</p>
<div class="content is-flex"> <div class="content is-flex">
<form class="pr-2" name="approve-{{ item.id }}" method="POST" action="{% url 'import-approve' job.id item.id %}"> <form class="pr-2" name="approve-{{ item.id }}" method="POST" action="{% url 'import-approve' job.id item.id %}">
{% csrf_token %} {% csrf_token %}

View file

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

View file

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