Make invite requests sort-able

This commit is contained in:
Mouse Reeve 2021-04-01 13:41:08 -07:00
parent 821baa5f18
commit b5e98e0bdf
2 changed files with 16 additions and 3 deletions

View file

@ -27,10 +27,17 @@
</h2>
<table class="table is-striped">
{% url 'settings-invite-requests' as url %}
<tr>
<th>{% trans "Date" %}</th>
<th>
{% trans "Date" as text %}
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
</th>
<th>{% trans "Email" %}</th>
<th>{% trans "Status" %}</th>
<th>
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="invite__times_used" sort=sort text=text %}
</th>
<th>{% trans "Action" %}</th>
</tr>
{% if not requests %}

View file

@ -92,9 +92,14 @@ class ManageInviteRequests(View):
except ValueError:
page = 1
sort = request.GET.get("sort")
sort_fields = ["created_date", "invite__times_used"]
if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
sort = "-created_date"
paginated = Paginator(
models.InviteRequest.objects.filter(ignored=ignored).order_by(
"-created_date"
sort
),
PAGE_LENGTH,
)
@ -103,6 +108,7 @@ class ManageInviteRequests(View):
"ignored": ignored,
"count": paginated.count,
"requests": paginated.page(page),
"sort": sort,
}
return TemplateResponse(request, "settings/manage_invite_requests.html", data)