forked from mirrors/bookwyrm
Helper for suggested users panel
This commit is contained in:
parent
732c7a190b
commit
7121b74a6e
4 changed files with 20 additions and 25 deletions
|
@ -6,7 +6,7 @@ from django.template.response import TemplateResponse
|
|||
from django.views import View
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from .helpers import get_suggested_users
|
||||
from .helpers import get_annotated_users
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
|
@ -29,7 +29,7 @@ class Directory(View):
|
|||
if scope == "local":
|
||||
filters["local"] = True
|
||||
|
||||
users = get_suggested_users(request.user, **filters)
|
||||
users = get_annotated_users(request.user, **filters)
|
||||
sort = request.GET.get("sort")
|
||||
if sort == "recent":
|
||||
users = users.order_by("-last_active_date")
|
||||
|
|
|
@ -34,17 +34,7 @@ class Feed(View):
|
|||
|
||||
paginated = Paginator(activities, PAGE_LENGTH)
|
||||
|
||||
suggested_users = (
|
||||
get_suggested_users(
|
||||
request.user,
|
||||
~Q(id=request.user.id),
|
||||
~Q(followers=request.user),
|
||||
~Q(follower_requests=request.user),
|
||||
bookwyrm_user=True,
|
||||
)
|
||||
.order_by("-mutuals", "-last_active_date")
|
||||
.all()[:5]
|
||||
)
|
||||
suggested_users = get_suggested_users(request.user)
|
||||
|
||||
data = {
|
||||
**feed_page_data(request.user),
|
||||
|
|
|
@ -120,17 +120,8 @@ class GetStartedUsers(View):
|
|||
)
|
||||
|
||||
if user_results.count() < 5:
|
||||
suggested_users = (
|
||||
get_suggested_users(
|
||||
request.user,
|
||||
~Q(id=request.user.id),
|
||||
~Q(followers=request.user),
|
||||
~Q(id__in=user_results),
|
||||
bookwyrm_user=True,
|
||||
)
|
||||
.order_by("shared_books", "-mutuals", "-last_active_date")
|
||||
.all()[: 5 - user_results.count()]
|
||||
)
|
||||
suggested_users = get_suggested_users(request.user)
|
||||
|
||||
data = {
|
||||
"suggested_users": list(user_results) + list(suggested_users),
|
||||
}
|
||||
|
|
|
@ -192,7 +192,21 @@ def get_discover_books():
|
|||
)
|
||||
|
||||
|
||||
def get_suggested_users(user, *args, **kwargs):
|
||||
def get_suggested_users(user):
|
||||
""" bookwyrm users you don't already know """
|
||||
return (
|
||||
get_annotated_users(
|
||||
user,
|
||||
~Q(id=user.id),
|
||||
~Q(followers=user),
|
||||
~Q(follower_requests=user),
|
||||
bookwyrm_user=True,
|
||||
)
|
||||
.order_by("-mutuals", "-last_active_date")
|
||||
.all()[:5]
|
||||
)
|
||||
|
||||
def get_annotated_users(user, *args, **kwargs):
|
||||
""" Users, annotated with things they have in common """
|
||||
return (
|
||||
models.User.objects.filter(discoverable=True, is_active=True, *args, **kwargs)
|
||||
|
|
Loading…
Reference in a new issue