mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Improves instance list admin view (#2068)
* Removes irrelevent initial federated server data * Adds secondary search order to instance list * Show last updated date * Adds filters to federated server view * Updates unit tests
This commit is contained in:
parent
ae86829a7e
commit
4c09477aa2
6 changed files with 52 additions and 23 deletions
|
@ -105,16 +105,6 @@ def init_connectors():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def init_federated_servers():
|
|
||||||
"""big no to nazis"""
|
|
||||||
built_in_blocks = ["gab.ai", "gab.com"]
|
|
||||||
for server in built_in_blocks:
|
|
||||||
models.FederatedServer.objects.create(
|
|
||||||
server_name=server,
|
|
||||||
status="blocked",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def init_settings():
|
def init_settings():
|
||||||
"""info about the instance"""
|
"""info about the instance"""
|
||||||
models.SiteSettings.objects.create(
|
models.SiteSettings.objects.create(
|
||||||
|
@ -163,7 +153,6 @@ class Command(BaseCommand):
|
||||||
"group",
|
"group",
|
||||||
"permission",
|
"permission",
|
||||||
"connector",
|
"connector",
|
||||||
"federatedserver",
|
|
||||||
"settings",
|
"settings",
|
||||||
"linkdomain",
|
"linkdomain",
|
||||||
]
|
]
|
||||||
|
@ -176,8 +165,6 @@ class Command(BaseCommand):
|
||||||
init_permissions()
|
init_permissions()
|
||||||
if not limit or limit == "connector":
|
if not limit or limit == "connector":
|
||||||
init_connectors()
|
init_connectors()
|
||||||
if not limit or limit == "federatedserver":
|
|
||||||
init_federated_servers()
|
|
||||||
if not limit or limit == "settings":
|
if not limit or limit == "settings":
|
||||||
init_settings()
|
init_settings()
|
||||||
if not limit or limit == "linkdomain":
|
if not limit or limit == "linkdomain":
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends 'snippets/filters_panel/filters_panel.html' %}
|
||||||
|
|
||||||
|
{% block filter_fields %}
|
||||||
|
{% include 'settings/federation/software_filter.html' %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
|
{% include 'settings/federation/instance_filters.html' %}
|
||||||
|
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<ul>
|
<ul>
|
||||||
{% url 'settings-federation' status='federated' as url %}
|
{% url 'settings-federation' status='federated' as url %}
|
||||||
|
@ -36,6 +39,10 @@
|
||||||
{% trans "Date added" as text %}
|
{% trans "Date added" as text %}
|
||||||
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
|
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
{% trans "Last updated" as text %}
|
||||||
|
{% include 'snippets/table-sort-header.html' with field="updated_date" sort=sort text=text %}
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
{% trans "Software" as text %}
|
{% trans "Software" as text %}
|
||||||
{% include 'snippets/table-sort-header.html' with field="application_type" sort=sort text=text %}
|
{% include 'snippets/table-sort-header.html' with field="application_type" sort=sort text=text %}
|
||||||
|
@ -43,12 +50,12 @@
|
||||||
<th>
|
<th>
|
||||||
{% trans "Users" %}
|
{% trans "Users" %}
|
||||||
</th>
|
</th>
|
||||||
<th>{% trans "Status" %}</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% for server in servers %}
|
{% for server in servers %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url 'settings-federated-server' server.id %}">{{ server.server_name }}</a></td>
|
<td><a href="{% url 'settings-federated-server' server.id %}">{{ server.server_name }}</a></td>
|
||||||
<td>{{ server.created_date }}</td>
|
<td>{{ server.created_date|date:'Y-m-d' }}</td>
|
||||||
|
<td>{{ server.updated_date|date:'Y-m-d' }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if server.application_type %}
|
{% if server.application_type %}
|
||||||
{{ server.application_type }}
|
{{ server.application_type }}
|
||||||
|
@ -56,7 +63,6 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ server.user_set.count }}</td>
|
<td>{{ server.user_set.count }}</td>
|
||||||
<td>{{ server.get_status_display }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not servers %}
|
{% if not servers %}
|
||||||
|
|
19
bookwyrm/templates/settings/federation/software_filter.html
Normal file
19
bookwyrm/templates/settings/federation/software_filter.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block filter %}
|
||||||
|
<label class="label" for="id_server">{% trans "Software" %}</label>
|
||||||
|
<div class="control">
|
||||||
|
<div class="select">
|
||||||
|
<select name="application_type">
|
||||||
|
<option value="">-----</option>
|
||||||
|
{% for option in software_options %}
|
||||||
|
{% if option %}
|
||||||
|
<option value="{{ option }}">{{ option }}</option>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -90,7 +90,6 @@ class InitDB(TestCase):
|
||||||
self.assertEqual(Group.objects.count(), 3)
|
self.assertEqual(Group.objects.count(), 3)
|
||||||
self.assertTrue(Permission.objects.exists())
|
self.assertTrue(Permission.objects.exists())
|
||||||
self.assertEqual(models.Connector.objects.count(), 3)
|
self.assertEqual(models.Connector.objects.count(), 3)
|
||||||
self.assertEqual(models.FederatedServer.objects.count(), 2)
|
|
||||||
self.assertEqual(models.SiteSettings.objects.count(), 1)
|
self.assertEqual(models.SiteSettings.objects.count(), 1)
|
||||||
self.assertEqual(models.LinkDomain.objects.count(), 5)
|
self.assertEqual(models.LinkDomain.objects.count(), 5)
|
||||||
|
|
||||||
|
@ -102,7 +101,6 @@ class InitDB(TestCase):
|
||||||
# everything should have been called
|
# everything should have been called
|
||||||
self.assertEqual(Group.objects.count(), 3)
|
self.assertEqual(Group.objects.count(), 3)
|
||||||
self.assertEqual(models.Connector.objects.count(), 0)
|
self.assertEqual(models.Connector.objects.count(), 0)
|
||||||
self.assertEqual(models.FederatedServer.objects.count(), 0)
|
|
||||||
self.assertEqual(models.SiteSettings.objects.count(), 0)
|
self.assertEqual(models.SiteSettings.objects.count(), 0)
|
||||||
self.assertEqual(models.LinkDomain.objects.count(), 0)
|
self.assertEqual(models.LinkDomain.objects.count(), 0)
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,23 @@ class Federation(View):
|
||||||
|
|
||||||
def get(self, request, status="federated"):
|
def get(self, request, status="federated"):
|
||||||
"""list of servers"""
|
"""list of servers"""
|
||||||
servers = models.FederatedServer.objects.filter(status=status)
|
|
||||||
|
filters = {}
|
||||||
|
if software := request.GET.get("application_type"):
|
||||||
|
filters["application_type"] = software
|
||||||
|
|
||||||
|
servers = models.FederatedServer.objects.filter(status=status, **filters)
|
||||||
|
|
||||||
sort = request.GET.get("sort")
|
sort = request.GET.get("sort")
|
||||||
sort_fields = ["created_date", "application_type", "server_name"]
|
sort_fields = [
|
||||||
# pylint: disable=consider-using-f-string
|
"created_date",
|
||||||
if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
"updated_date",
|
||||||
|
"application_type",
|
||||||
|
"server_name",
|
||||||
|
]
|
||||||
|
if not sort in sort_fields + [f"-{f}" for f in sort_fields]:
|
||||||
sort = "-created_date"
|
sort = "-created_date"
|
||||||
servers = servers.order_by(sort)
|
servers = servers.order_by(sort, "-created_date")
|
||||||
|
|
||||||
paginated = Paginator(servers, PAGE_LENGTH)
|
paginated = Paginator(servers, PAGE_LENGTH)
|
||||||
page = paginated.get_page(request.GET.get("page"))
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
@ -49,6 +58,9 @@ class Federation(View):
|
||||||
page.number, on_each_side=2, on_ends=1
|
page.number, on_each_side=2, on_ends=1
|
||||||
),
|
),
|
||||||
"sort": sort,
|
"sort": sort,
|
||||||
|
"software_options": models.FederatedServer.objects.values_list(
|
||||||
|
"application_type", flat=True
|
||||||
|
).distinct(),
|
||||||
"form": forms.ServerForm(),
|
"form": forms.ServerForm(),
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "settings/federation/instance_list.html", data)
|
return TemplateResponse(request, "settings/federation/instance_list.html", data)
|
||||||
|
|
Loading…
Reference in a new issue