moviewyrm/bookwyrm/views/directory.py

49 lines
1.6 KiB
Python
Raw Normal View History

2021-03-21 23:37:52 +00:00
""" who all's here? """
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
2021-03-25 15:39:45 +00:00
from django.shortcuts import redirect
2021-03-21 23:37:52 +00:00
from django.template.response import TemplateResponse
from django.views import View
from django.utils.decorators import method_decorator
from bookwyrm import suggested_users
2021-03-21 23:37:52 +00:00
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
class Directory(View):
2021-04-26 16:15:42 +00:00
"""display of known bookwyrm users"""
2021-03-21 23:37:52 +00:00
def get(self, request):
2021-04-26 16:15:42 +00:00
"""lets see your cute faces"""
2021-03-25 20:36:35 +00:00
filters = {}
software = request.GET.get("software")
if not software or software == "bookwyrm":
2021-03-25 20:36:35 +00:00
filters["bookwyrm_user"] = True
scope = request.GET.get("scope")
if scope == "local":
filters["local"] = True
users = suggested_users.get_annotated_users(request.user, **filters)
2021-03-25 20:36:35 +00:00
sort = request.GET.get("sort")
if sort == "recent":
users = users.order_by("-last_active_date")
else:
2021-08-06 16:40:01 +00:00
users = users.order_by("-mutuals", "-last_active_date")
2021-03-25 20:36:35 +00:00
2021-03-21 23:37:52 +00:00
paginated = Paginator(users, 12)
page = paginated.get_page(request.GET.get("page"))
2021-03-21 23:37:52 +00:00
data = {
"page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
),
"users": page,
2021-03-21 23:37:52 +00:00
}
2021-03-29 17:39:13 +00:00
return TemplateResponse(request, "directory/directory.html", data)
2021-03-25 15:39:45 +00:00
def post(self, request):
2021-04-26 16:15:42 +00:00
"""join the directory"""
2021-03-25 15:39:45 +00:00
request.user.discoverable = True
request.user.save()
2021-03-25 19:04:26 +00:00
return redirect("directory")