forked from mirrors/bookwyrm
Paginates results
This commit is contained in:
parent
88e915409b
commit
951b611881
2 changed files with 11 additions and 1 deletions
|
@ -44,5 +44,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% include 'snippets/pagination.html' with page=reports path=request.path %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
""" moderation via flagged posts and users """
|
""" moderation via flagged posts and users """
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -7,6 +8,7 @@ from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
|
@ -34,10 +36,17 @@ class ReportsAdmin(View):
|
||||||
if username:
|
if username:
|
||||||
filters["user__username__icontains"] = username
|
filters["user__username__icontains"] = username
|
||||||
filters["resolved"] = resolved
|
filters["resolved"] = resolved
|
||||||
|
|
||||||
|
reports = models.Report.objects.filter(**filters)
|
||||||
|
paginated = Paginator(reports, PAGE_LENGTH)
|
||||||
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
data = {
|
data = {
|
||||||
"resolved": resolved,
|
"resolved": resolved,
|
||||||
"server": server,
|
"server": server,
|
||||||
"reports": models.Report.objects.filter(**filters),
|
"reports": page,
|
||||||
|
"page_range": paginated.get_elided_page_range(
|
||||||
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
),
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "settings/reports/reports.html", data)
|
return TemplateResponse(request, "settings/reports/reports.html", data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue