From f491f03ffa5dcedc7fda31c4785b659a645a84e7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 28 Mar 2021 14:27:56 -0700 Subject: [PATCH] Adds filtering by server on users page --- bookwyrm/templates/settings/federated_server.html | 2 +- bookwyrm/templates/settings/user_admin.html | 9 ++++++++- bookwyrm/views/user_admin.py | 11 +++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/settings/federated_server.html b/bookwyrm/templates/settings/federated_server.html index 7d65309b..13715bfb 100644 --- a/bookwyrm/templates/settings/federated_server.html +++ b/bookwyrm/templates/settings/federated_server.html @@ -33,7 +33,7 @@
{% trans "Users:" %}
{{ users.count }} - {# {% if server.user_set.count %}({% trans "View all users" %}){% endif %} #} + {% if server.user_set.count %}({% trans "View all" %}){% endif %}
diff --git a/bookwyrm/templates/settings/user_admin.html b/bookwyrm/templates/settings/user_admin.html index eba7fbf7..bb0534e0 100644 --- a/bookwyrm/templates/settings/user_admin.html +++ b/bookwyrm/templates/settings/user_admin.html @@ -2,7 +2,14 @@ {% load i18n %} {% block title %}{% trans "Users" %}{% endblock %} -{% block header %}{% trans "Users" %}{% endblock %} +{% block header %} +{% if server %} +{% blocktrans with server_name=server.server_name %}Users: {{ server_name }}{% endblocktrans %} +Clear filters +{% else %} +{% trans "Users" %} +{% endif %} +{% endblock %} {% block panel %} diff --git a/bookwyrm/views/user_admin.py b/bookwyrm/views/user_admin.py index 491b8150..a8c155a1 100644 --- a/bookwyrm/views/user_admin.py +++ b/bookwyrm/views/user_admin.py @@ -1,6 +1,7 @@ """ manage user """ from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator +from django.shortcuts import get_object_or_404 from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -25,7 +26,13 @@ class UserAdmin(View): except ValueError: page = 1 - users = models.User.objects.all() + filters = {} + server = request.GET.get("server") + if server: + server = get_object_or_404(models.FederatedServer, id=server) + filters["federated_server"] = server + + users = models.User.objects.filter(**filters).all() sort = request.GET.get("sort", "-created_date") sort_fields = [ @@ -39,5 +46,5 @@ class UserAdmin(View): users = users.order_by(sort) paginated = Paginator(users, PAGE_LENGTH) - data = {"users": paginated.page(page), "sort": sort} + data = {"users": paginated.page(page), "sort": sort, "server": server} return TemplateResponse(request, "settings/user_admin.html", data)