mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-15 13:24:04 +00:00
Merge pull request #2338 from bookwyrm-social/sort-admin-imports
Make the import admin table sortable
This commit is contained in:
commit
cc95c4d7b5
2 changed files with 16 additions and 3 deletions
|
@ -29,15 +29,17 @@
|
|||
<div class="table-container block content">
|
||||
<table class="table is-striped is-fullwidth">
|
||||
<tr>
|
||||
{% url 'settings-imports' as url %}
|
||||
{% url 'settings-imports' status as url %}
|
||||
<th>
|
||||
{% trans "ID" %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "User" %}
|
||||
{% trans "User" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="user" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Date Created" %}
|
||||
{% trans "Date Created" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
|
||||
</th>
|
||||
{% if status != "active" %}
|
||||
<th>
|
||||
|
|
|
@ -22,9 +22,19 @@ class ImportList(View):
|
|||
def get(self, request, status="active"):
|
||||
"""list of imports"""
|
||||
complete = status == "complete"
|
||||
|
||||
sort = request.GET.get("sort", "created_date")
|
||||
sort_fields = [
|
||||
"created_date",
|
||||
"user",
|
||||
]
|
||||
imports = models.ImportJob.objects.filter(complete=complete).order_by(
|
||||
"created_date"
|
||||
)
|
||||
# pylint: disable=consider-using-f-string
|
||||
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
imports = imports.order_by(sort)
|
||||
|
||||
paginated = Paginator(imports, PAGE_LENGTH)
|
||||
page = paginated.get_page(request.GET.get("page"))
|
||||
data = {
|
||||
|
@ -33,6 +43,7 @@ class ImportList(View):
|
|||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
"status": status,
|
||||
"sort": sort,
|
||||
}
|
||||
return TemplateResponse(request, "settings/imports/imports.html", data)
|
||||
|
||||
|
|
Loading…
Reference in a new issue