Separate admin user list into tabbed lists

This commit is contained in:
Mouse Reeve 2022-03-14 09:27:18 -07:00
parent bf68b70fba
commit 488d702473
3 changed files with 71 additions and 40 deletions

View file

@ -1,5 +1,7 @@
{% extends 'settings/layout.html' %}
{% load i18n %}
{% load utilities %}
{% block title %}{% trans "Users" %}{% endblock %}
{% block header %}
@ -15,46 +17,67 @@
{% include 'settings/users/user_admin_filters.html' %}
<table class="table is-striped">
<tr>
{% url 'settings-users' as url %}
<th>
{% trans "Username" as text %}
{% include 'snippets/table-sort-header.html' with field="username" sort=sort text=text %}
</th>
<th>
{% trans "Date Added" as text %}
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
</th>
<th>
{% trans "Last Active" as text %}
{% include 'snippets/table-sort-header.html' with field="last_active_date" sort=sort text=text %}
</th>
<th>
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="is_active" sort=sort text=text %}
</th>
<th>
{% trans "Remote instance" as text %}
{% include 'snippets/table-sort-header.html' with field="federated_server__server_name" sort=sort text=text %}
</th>
</tr>
{% for user in users %}
<tr>
<td><a href="{% url 'settings-user' user.id %}">{{ user.username }}</a></td>
<td>{{ user.created_date }}</td>
<td>{{ user.last_active_date }}</td>
<td>{% if user.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}</td>
<td>
{% if user.federated_server %}
<a href="{% url 'settings-federated-server' user.federated_server.id %}">{{ user.federated_server.server_name }}</a>
{% elif not user.local %}
<em>{% trans "Not set" %}</em>
<div class="block">
<div class="tabs">
<ul>
{% url 'settings-users' as url %}
<li {% if request.path in url %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Local users" %}</a>
</li>
{% url 'settings-users' status="federated" as url %}
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Federated community" %}</a>
</li>
</ul>
</div>
</div>
<div class="table-container block">
<table class="table is-striped">
<tr>
{% url 'settings-users' as url %}
<th>
{% trans "Username" as text %}
{% include 'snippets/table-sort-header.html' with field="username" sort=sort text=text %}
</th>
<th>
{% trans "Date Added" as text %}
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
</th>
<th>
{% trans "Last Active" as text %}
{% include 'snippets/table-sort-header.html' with field="last_active_date" sort=sort text=text %}
</th>
<th>
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="is_active" sort=sort text=text %}
</th>
{% if status != "local" %}
<th>
{% trans "Remote instance" as text %}
{% include 'snippets/table-sort-header.html' with field="federated_server__server_name" sort=sort text=text %}
</th>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</tr>
{% for user in users %}
<tr>
<td><a href="{% url 'settings-user' user.id %}">{{ user|username }}</a></td>
<td>{{ user.created_date }}</td>
<td>{{ user.last_active_date }}</td>
<td>{% if user.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}</td>
{% if status != "local" %}
<td>
{% if user.federated_server %}
<a href="{% url 'settings-federated-server' user.federated_server.id %}">{{ user.federated_server.server_name }}</a>
{% else %}
<em>{% trans "Not set" %}</em>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
{% include 'snippets/pagination.html' with page=users path=request.path %}
{% endblock %}

View file

@ -125,6 +125,11 @@ urlpatterns = [
re_path(
r"^settings/users/?$", views.UserAdminList.as_view(), name="settings-users"
),
re_path(
r"^settings/users/(?P<status>(local|federated))\/?$",
views.UserAdminList.as_view(),
name="settings-users",
),
re_path(
r"^settings/users/(?P<user>\d+)/?$",
views.UserAdmin.as_view(),

View file

@ -19,7 +19,7 @@ from bookwyrm.settings import PAGE_LENGTH
class UserAdminList(View):
"""admin view of users on this server"""
def get(self, request):
def get(self, request, status="local"):
"""list of users"""
filters = {}
server = request.GET.get("server")
@ -37,6 +37,8 @@ class UserAdminList(View):
if email:
filters["email__endswith"] = email
filters["local"] = status == "local"
users = models.User.objects.filter(**filters)
sort = request.GET.get("sort", "-created_date")
@ -56,6 +58,7 @@ class UserAdminList(View):
"users": paginated.get_page(request.GET.get("page")),
"sort": sort,
"server": server,
"status": status,
}
return TemplateResponse(request, "settings/users/user_admin.html", data)