forked from mirrors/bookwyrm
Filter reports and users by server name and username
This commit is contained in:
parent
46cf885475
commit
10cf189312
9 changed files with 43 additions and 9 deletions
|
@ -8,6 +8,7 @@
|
|||
{% trans "Reports" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{% if server %}
|
||||
{% blocktrans with server_name=server.server_name %}Reports: <small>{{ server_name }}</small>{% endblocktrans %}
|
||||
|
@ -29,6 +30,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
{% include 'settings/user_admin_filters.html' %}
|
||||
|
||||
<div class="block">
|
||||
{% if not reports %}
|
||||
<em>{% trans "No reports found." %}</em>
|
||||
|
|
|
@ -39,14 +39,14 @@
|
|||
<dt>{% trans "Users:" %}</dt>
|
||||
<dd>
|
||||
{{ users.count }}
|
||||
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="is-flex">
|
||||
<dt>{% trans "Reports:" %}</dt>
|
||||
<dd>
|
||||
{{ reports.count }}
|
||||
{% if reports.count %}(<a href="{% url 'settings-reports' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||
{% if reports.count %}(<a href="{% url 'settings-reports' %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="is-flex">
|
||||
|
|
7
bookwyrm/templates/settings/server_filter.html
Normal file
7
bookwyrm/templates/settings/server_filter.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label" for="id_server">{% trans "Server name" %}</label>
|
||||
<input type="text" class="input" name="server" value="{{ request.GET.server|default:'' }}" id="id_server" placeholder="example.server.com">
|
||||
{% endblock %}
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
{% block panel %}
|
||||
|
||||
{% include 'settings/user_admin_filters.html' %}
|
||||
|
||||
<table class="table is-striped">
|
||||
<tr>
|
||||
{% url 'settings-users' as url %}
|
||||
|
|
6
bookwyrm/templates/settings/user_admin_filters.html
Normal file
6
bookwyrm/templates/settings/user_admin_filters.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends 'snippets/filters_panel/filters_panel.html' %}
|
||||
|
||||
{% block filter_fields %}
|
||||
{% include 'settings/server_filter.html' %}
|
||||
{% include 'settings/username_filter.html' %}
|
||||
{% endblock %}
|
8
bookwyrm/templates/settings/username_filter.html
Normal file
8
bookwyrm/templates/settings/username_filter.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label" for="id_username">{% trans "Username" %}</label>
|
||||
<input type="text" class="input" name="username" value="{{ request.GET.username|default:'' }}" id="id_username" placeholder="user@domain.com">
|
||||
{% endblock %}
|
||||
|
|
@ -29,7 +29,7 @@ class Federation(View):
|
|||
except ValueError:
|
||||
page = 1
|
||||
|
||||
servers = models.FederatedServer.objects.all()
|
||||
servers = models.FederatedServer.objects
|
||||
|
||||
sort = request.GET.get("sort")
|
||||
sort_fields = ["created_date", "application_type", "server_name"]
|
||||
|
|
|
@ -29,8 +29,10 @@ class Reports(View):
|
|||
resolved = request.GET.get("resolved") == "true"
|
||||
server = request.GET.get("server")
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
filters["user__federated_server"] = server
|
||||
filters["user__federated_server__server_name"] = server
|
||||
username = request.GET.get("username")
|
||||
if username:
|
||||
filters["user__username__icontains"] = username
|
||||
filters["resolved"] = resolved
|
||||
data = {
|
||||
"resolved": resolved,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
""" 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
|
||||
|
@ -29,10 +28,14 @@ class UserAdmin(View):
|
|||
filters = {}
|
||||
server = request.GET.get("server")
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
server = models.FederatedServer.objects.filter(server_name=server).first()
|
||||
filters["federated_server"] = server
|
||||
filters["federated_server__isnull"] = False
|
||||
username = request.GET.get("username")
|
||||
if username:
|
||||
filters["username__icontains"] = username
|
||||
|
||||
users = models.User.objects.filter(**filters).all()
|
||||
users = models.User.objects.filter(**filters)
|
||||
|
||||
sort = request.GET.get("sort", "-created_date")
|
||||
sort_fields = [
|
||||
|
@ -46,5 +49,8 @@ class UserAdmin(View):
|
|||
users = users.order_by(sort)
|
||||
|
||||
paginated = Paginator(users, PAGE_LENGTH)
|
||||
data = {"users": paginated.get_page(page), "sort": sort, "server": server}
|
||||
data = {
|
||||
"users": paginated.get_page(page),
|
||||
"sort": sort, "server": server,
|
||||
}
|
||||
return TemplateResponse(request, "settings/user_admin.html", data)
|
||||
|
|
Loading…
Reference in a new issue