Add pagination and search to federation page
This commit is contained in:
parent
f22869693a
commit
e2d28a4be0
|
@ -428,6 +428,11 @@ form.follow button {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.search {
|
||||||
|
display: flex;
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
form h1 {
|
form h1 {
|
||||||
margin: 0 0 10px 0;
|
margin: 0 0 10px 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
{% block subtitle %}Federation{% endblock %}
|
{% block subtitle %}Federation{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<form action="." class="search">
|
||||||
|
<input type="search" name="query" value="{{ query }}" placeholder="Search by domain">
|
||||||
|
<button><i class="fa-solid fa-search"></i></button>
|
||||||
|
</form>
|
||||||
<section class="icon-menu">
|
<section class="icon-menu">
|
||||||
{% for domain in domains %}
|
{% for domain in page_obj %}
|
||||||
<a class="option" href="{{ domain.urls.edit_federation }}">
|
<a class="option" href="{{ domain.urls.edit_federation }}">
|
||||||
<i class="fa-solid fa-globe"></i>
|
<i class="fa-solid fa-globe"></i>
|
||||||
<span class="handle">
|
<span class="handle">
|
||||||
|
@ -20,5 +24,13 @@
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<p class="option empty">There are no federation links yet.</p>
|
<p class="option empty">There are no federation links yet.</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<div class="load-more">
|
||||||
|
{% if page_obj.has_previous %}
|
||||||
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,24 +2,35 @@ from django import forms
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.decorators import method_decorator
|
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.decorators import admin_required
|
||||||
from users.models import Domain
|
from users.models import Domain
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(admin_required, name="dispatch")
|
@method_decorator(admin_required, name="dispatch")
|
||||||
class FederationRoot(TemplateView):
|
class FederationRoot(ListView):
|
||||||
|
|
||||||
template_name = "admin/federation.html"
|
template_name = "admin/federation.html"
|
||||||
|
paginate_by = 50
|
||||||
|
|
||||||
def get_context_data(self):
|
def get(self, request, *args, **kwargs):
|
||||||
return {
|
self.query = request.GET.get("query")
|
||||||
"domains": Domain.objects.filter(local=False)
|
self.extra_context = {
|
||||||
.annotate(num_users=models.Count("identities"))
|
|
||||||
.order_by("domain"),
|
|
||||||
"section": "federation",
|
"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")
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
|
Loading…
Reference in New Issue