From e2d28a4be08ccc629def8c85327b657b0bf36f90 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 5 Dec 2022 19:54:47 -0700 Subject: Add pagination and search to federation page --- static/css/style.css | 5 +++++ templates/admin/federation.html | 14 +++++++++++++- users/views/admin/federation.py | 25 ++++++++++++++++++------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index 7b62b5b..e29126b 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -428,6 +428,11 @@ form.follow button { margin: 0; } +form.search { + display: flex; + margin: 0 0 20px 0; +} + form h1 { margin: 0 0 10px 0; } diff --git a/templates/admin/federation.html b/templates/admin/federation.html index 1a48176..98ee09d 100644 --- a/templates/admin/federation.html +++ b/templates/admin/federation.html @@ -3,8 +3,12 @@ {% block subtitle %}Federation{% endblock %} {% block content %} +
- {% for domain in domains %} + {% for domain in page_obj %} @@ -20,5 +24,13 @@ {% empty %}

There are no federation links yet.

{% endfor %} +
+ {% if page_obj.has_previous %} + Previous Page + {% endif %} + {% if page_obj.has_next %} + Next Page + {% endif %} +
{% endblock %} diff --git a/users/views/admin/federation.py b/users/views/admin/federation.py index 4d6b179..0611b9e 100644 --- a/users/views/admin/federation.py +++ b/users/views/admin/federation.py @@ -2,24 +2,35 @@ from django import forms from django.db import models from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator -from django.views.generic import FormView, TemplateView +from django.views.generic import FormView, ListView from users.decorators import admin_required from users.models import Domain @method_decorator(admin_required, name="dispatch") -class FederationRoot(TemplateView): +class FederationRoot(ListView): template_name = "admin/federation.html" + paginate_by = 50 - def get_context_data(self): - return { - "domains": Domain.objects.filter(local=False) - .annotate(num_users=models.Count("identities")) - .order_by("domain"), + def get(self, request, *args, **kwargs): + self.query = request.GET.get("query") + self.extra_context = { "section": "federation", + "query": self.query or "", } + return super().get(request, *args, **kwargs) + + def get_queryset(self): + domains = ( + Domain.objects.filter(local=False) + .annotate(num_users=models.Count("identities")) + .order_by("domain") + ) + if self.query: + domains = domains.filter(domain__icontains=self.query) + return domains @method_decorator(admin_required, name="dispatch") -- cgit v1.2.3