moviewyrm/bookwyrm/views/directory.py

45 lines
1.5 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
2021-04-02 02:56:53 +00:00
from .helpers import get_annotated_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
2021-04-02 02:56:53 +00:00
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:
users = users.order_by("-mutuals", "-shared_books", "-last_active_date")
2021-03-25 20:36:35 +00:00
2021-03-21 23:37:52 +00:00
paginated = Paginator(users, 12)
data = {
2021-04-19 22:01:20 +00:00
"users": paginated.get_page(request.GET.get("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")