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
|
|
|
|
|
2021-04-24 01:26:48 +00:00
|
|
|
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")
|
2021-03-26 00:00:16 +00:00
|
|
|
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
|
|
|
|
|
2021-04-24 01:26:48 +00:00
|
|
|
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)
|
|
|
|
|
2021-08-02 23:15:14 +00:00
|
|
|
page = paginated.get_page(request.GET.get("page"))
|
2021-03-21 23:37:52 +00:00
|
|
|
data = {
|
2021-08-02 23:15:14 +00:00
|
|
|
"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
|
2021-05-22 18:53:20 +00:00
|
|
|
request.user.save()
|
2021-03-25 19:04:26 +00:00
|
|
|
return redirect("directory")
|