forked from mirrors/bookwyrm
Adds filtering by server on users page
This commit is contained in:
parent
43fc940a07
commit
f491f03ffa
3 changed files with 18 additions and 4 deletions
|
@ -33,7 +33,7 @@
|
||||||
<dt>{% trans "Users:" %}</dt>
|
<dt>{% trans "Users:" %}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{ users.count }}
|
{{ users.count }}
|
||||||
{# {% if server.user_set.count %}(<a href="{% url 'settings-users' server=server.id %}">{% trans "View all users" %}</a>){% endif %} #}
|
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="is-flex">
|
<div class="is-flex">
|
||||||
|
|
|
@ -2,7 +2,14 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block title %}{% trans "Users" %}{% endblock %}
|
{% block title %}{% trans "Users" %}{% endblock %}
|
||||||
|
|
||||||
{% block header %}{% trans "Users" %}{% endblock %}
|
{% block header %}
|
||||||
|
{% if server %}
|
||||||
|
{% blocktrans with server_name=server.server_name %}Users: <small>{{ server_name }}</small>{% endblocktrans %}
|
||||||
|
<a href="{% url 'settings-users' %}" class="help has-text-weight-normal">Clear filters</a>
|
||||||
|
{% else %}
|
||||||
|
{% trans "Users" %}
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
""" manage user """
|
""" manage user """
|
||||||
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.paginator import Paginator
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
@ -25,7 +26,13 @@ class UserAdmin(View):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
users = models.User.objects.all()
|
filters = {}
|
||||||
|
server = request.GET.get("server")
|
||||||
|
if server:
|
||||||
|
server = get_object_or_404(models.FederatedServer, id=server)
|
||||||
|
filters["federated_server"] = server
|
||||||
|
|
||||||
|
users = models.User.objects.filter(**filters).all()
|
||||||
|
|
||||||
sort = request.GET.get("sort", "-created_date")
|
sort = request.GET.get("sort", "-created_date")
|
||||||
sort_fields = [
|
sort_fields = [
|
||||||
|
@ -39,5 +46,5 @@ class UserAdmin(View):
|
||||||
users = users.order_by(sort)
|
users = users.order_by(sort)
|
||||||
|
|
||||||
paginated = Paginator(users, PAGE_LENGTH)
|
paginated = Paginator(users, PAGE_LENGTH)
|
||||||
data = {"users": paginated.page(page), "sort": sort}
|
data = {"users": paginated.page(page), "sort": sort, "server": server}
|
||||||
return TemplateResponse(request, "settings/user_admin.html", data)
|
return TemplateResponse(request, "settings/user_admin.html", data)
|
||||||
|
|
Loading…
Reference in a new issue