moviewyrm/bookwyrm/views/directory.py

51 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 .helpers import get_suggested_users
2021-03-21 23:37:52 +00:00
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
class Directory(View):
""" display of known bookwyrm users """
def get(self, request):
""" lets see your cute faces """
try:
page = int(request.GET.get("page", 1))
except ValueError:
page = 1
2021-03-25 20:36:35 +00:00
# filters
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 = get_suggested_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 = {
"users": paginated.page(page),
}
return TemplateResponse(request, "directory.html", data)
2021-03-25 15:39:45 +00:00
def post(self, request):
""" join the directory """
request.user.discoverable = True
request.user.save()
2021-03-25 19:04:26 +00:00
return redirect("directory")