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():
|
||||
"""info about the instance"""
|
||||
models.SiteSettings.objects.create(
|
||||
|
@ -163,7 +153,6 @@ class Command(BaseCommand):
|
|||
"group",
|
||||
"permission",
|
||||
"connector",
|
||||
"federatedserver",
|
||||
"settings",
|
||||
"linkdomain",
|
||||
]
|
||||
|
@ -176,8 +165,6 @@ class Command(BaseCommand):
|
|||
init_permissions()
|
||||
if not limit or limit == "connector":
|
||||
init_connectors()
|
||||
if not limit or limit == "federatedserver":
|
||||
init_federated_servers()
|
||||
if not limit or limit == "settings":
|
||||
init_settings()
|
||||
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 %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% include 'settings/federation/instance_filters.html' %}
|
||||
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
{% url 'settings-federation' status='federated' as url %}
|
||||
|
@ -36,6 +39,10 @@
|
|||
{% trans "Date added" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Last updated" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="updated_date" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Software" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="application_type" sort=sort text=text %}
|
||||
|
@ -43,12 +50,12 @@
|
|||
<th>
|
||||
{% trans "Users" %}
|
||||
</th>
|
||||
<th>{% trans "Status" %}</th>
|
||||
</tr>
|
||||
{% for server in servers %}
|
||||
<tr>
|
||||
<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>
|
||||
{% if server.application_type %}
|
||||
{{ server.application_type }}
|
||||
|
@ -56,7 +63,6 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
<td>{{ server.user_set.count }}</td>
|
||||
<td>{{ server.get_status_display }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% 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.assertTrue(Permission.objects.exists())
|
||||
self.assertEqual(models.Connector.objects.count(), 3)
|
||||
self.assertEqual(models.FederatedServer.objects.count(), 2)
|
||||
self.assertEqual(models.SiteSettings.objects.count(), 1)
|
||||
self.assertEqual(models.LinkDomain.objects.count(), 5)
|
||||
|
||||
|
@ -102,7 +101,6 @@ class InitDB(TestCase):
|
|||
# everything should have been called
|
||||
self.assertEqual(Group.objects.count(), 3)
|
||||
self.assertEqual(models.Connector.objects.count(), 0)
|
||||
self.assertEqual(models.FederatedServer.objects.count(), 0)
|
||||
self.assertEqual(models.SiteSettings.objects.count(), 0)
|
||||
self.assertEqual(models.LinkDomain.objects.count(), 0)
|
||||
|
||||
|
|
|
@ -25,14 +25,23 @@ class Federation(View):
|
|||
|
||||
def get(self, request, status="federated"):
|
||||
"""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_fields = ["created_date", "application_type", "server_name"]
|
||||
# pylint: disable=consider-using-f-string
|
||||
if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
sort_fields = [
|
||||
"created_date",
|
||||
"updated_date",
|
||||
"application_type",
|
||||
"server_name",
|
||||
]
|
||||
if not sort in sort_fields + [f"-{f}" for f in sort_fields]:
|
||||
sort = "-created_date"
|
||||
servers = servers.order_by(sort)
|
||||
servers = servers.order_by(sort, "-created_date")
|
||||
|
||||
paginated = Paginator(servers, PAGE_LENGTH)
|
||||
page = paginated.get_page(request.GET.get("page"))
|
||||
|
@ -49,6 +58,9 @@ class Federation(View):
|
|||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
"sort": sort,
|
||||
"software_options": models.FederatedServer.objects.values_list(
|
||||
"application_type", flat=True
|
||||
).distinct(),
|
||||
"form": forms.ServerForm(),
|
||||
}
|
||||
return TemplateResponse(request, "settings/federation/instance_list.html", data)
|
||||
|
|
Loading…
Reference in a new issue