mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Sort federated servers list
This commit is contained in:
parent
158d2c5231
commit
7373a7e8c4
3 changed files with 34 additions and 3 deletions
|
@ -8,13 +8,25 @@
|
|||
|
||||
<table class="table is-striped">
|
||||
<tr>
|
||||
<th>{% trans "Server name" %}</th>
|
||||
<th>{% trans "Software" %}</th>
|
||||
{% url 'settings-federation' as url %}
|
||||
<th>
|
||||
{% trans "Server name" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="server_name" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Date federated" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="created_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 %}
|
||||
</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.application_type }} ({{ server.application_version }})</td>
|
||||
<td>{{ server.status }}</td>
|
||||
</tr>
|
||||
|
|
13
bookwyrm/templates/snippets/table-sort-header.html
Normal file
13
bookwyrm/templates/snippets/table-sort-header.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% load i18n %}
|
||||
<a href="{{ url }}?sort={% if sort == field %}-{% endif %}{{ field }}">
|
||||
{{ text }}
|
||||
{% if sort == field %}
|
||||
<span class="icon icon-arrow-down">
|
||||
<span class="is-sr-only">{% trans "Sorted asccending" %}</span>
|
||||
</span>
|
||||
{% elif sort == "-"|add:field %}
|
||||
<span class="icon icon-arrow-up">
|
||||
<span class="is-sr-only">{% trans "Sorted descending" %}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</a>
|
|
@ -27,8 +27,14 @@ class Federation(View):
|
|||
page = 1
|
||||
|
||||
servers = models.FederatedServer.objects.all()
|
||||
|
||||
sort = request.GET.get('sort')
|
||||
sort_fields = ['created_date', 'application_type', 'server_name']
|
||||
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
servers = servers.order_by(sort)
|
||||
|
||||
paginated = Paginator(servers, PAGE_LENGTH)
|
||||
data = {"servers": paginated.page(page)}
|
||||
data = {"servers": paginated.page(page), "sort": sort}
|
||||
return TemplateResponse(request, "settings/federation.html", data)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue