From b5e98e0bdf360fe1b3df769e2f64f3a8965c798d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 13:41:08 -0700 Subject: [PATCH 1/4] Make invite requests sort-able --- .../templates/settings/manage_invite_requests.html | 11 +++++++++-- bookwyrm/views/invite.py | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/settings/manage_invite_requests.html b/bookwyrm/templates/settings/manage_invite_requests.html index 7a7088d9b..76c1a6090 100644 --- a/bookwyrm/templates/settings/manage_invite_requests.html +++ b/bookwyrm/templates/settings/manage_invite_requests.html @@ -27,10 +27,17 @@ + {% url 'settings-invite-requests' as url %} - + - + {% if not requests %} diff --git a/bookwyrm/views/invite.py b/bookwyrm/views/invite.py index 49b5c91b1..a99a7de0e 100644 --- a/bookwyrm/views/invite.py +++ b/bookwyrm/views/invite.py @@ -92,9 +92,14 @@ class ManageInviteRequests(View): except ValueError: page = 1 + sort = request.GET.get("sort") + sort_fields = ["created_date", "invite__times_used"] + if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: + sort = "-created_date" + paginated = Paginator( models.InviteRequest.objects.filter(ignored=ignored).order_by( - "-created_date" + sort ), PAGE_LENGTH, ) @@ -103,6 +108,7 @@ class ManageInviteRequests(View): "ignored": ignored, "count": paginated.count, "requests": paginated.page(page), + "sort": sort, } return TemplateResponse(request, "settings/manage_invite_requests.html", data) From 8039917b891ffffc2aa60ecc9adda6439c17a82a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 13:55:10 -0700 Subject: [PATCH 2/4] Preserve get params on invite send --- .../templates/settings/manage_invite_requests.html | 2 +- bookwyrm/views/invite.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bookwyrm/templates/settings/manage_invite_requests.html b/bookwyrm/templates/settings/manage_invite_requests.html index 76c1a6090..23c64002d 100644 --- a/bookwyrm/templates/settings/manage_invite_requests.html +++ b/bookwyrm/templates/settings/manage_invite_requests.html @@ -57,7 +57,7 @@ {% endif %}
{% trans "Date" %} + {% trans "Date" as text %} + {% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %} + {% trans "Email" %}{% trans "Status" %} + {% trans "Status" as text %} + {% include 'snippets/table-sort-header.html' with field="invite__times_used" sort=sort text=text %} + {% trans "Action" %}
-
+ {% csrf_token %} {% if not req.invite %} diff --git a/bookwyrm/views/invite.py b/bookwyrm/views/invite.py index a99a7de0e..1f5492c6c 100644 --- a/bookwyrm/views/invite.py +++ b/bookwyrm/views/invite.py @@ -1,9 +1,12 @@ """ invites when registration is closed """ +from urllib.parse import urlencode + from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator from django.http import HttpResponseBadRequest from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse +from django.urls import reverse from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.http import require_POST @@ -98,9 +101,7 @@ class ManageInviteRequests(View): sort = "-created_date" paginated = Paginator( - models.InviteRequest.objects.filter(ignored=ignored).order_by( - sort - ), + models.InviteRequest.objects.filter(ignored=ignored).order_by(sort), PAGE_LENGTH, ) @@ -125,7 +126,11 @@ class ManageInviteRequests(View): ) invite_request.save() emailing.invite_email(invite_request) - return redirect("settings-invite-requests") + return redirect( + "{:s}?{:s}".format( + reverse("settings-invite-requests"), urlencode(request.GET.dict()) + ) + ) class InviteRequest(View): From b62989b5a8c68b21da13dffdd4deb97466ff463d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 14:14:17 -0700 Subject: [PATCH 3/4] Adds invite request filters --- .../settings/manage_invite_requests.html | 2 ++ bookwyrm/views/invite.py | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/settings/manage_invite_requests.html b/bookwyrm/templates/settings/manage_invite_requests.html index 23c64002d..03ddd2104 100644 --- a/bookwyrm/templates/settings/manage_invite_requests.html +++ b/bookwyrm/templates/settings/manage_invite_requests.html @@ -26,6 +26,8 @@ {% endif %} ({{ count }}) + {% include 'settings/invite_request_filters.html' %} + {% url 'settings-invite-requests' as url %} diff --git a/bookwyrm/views/invite.py b/bookwyrm/views/invite.py index 1f5492c6c..0be48675e 100644 --- a/bookwyrm/views/invite.py +++ b/bookwyrm/views/invite.py @@ -1,8 +1,11 @@ """ invites when registration is closed """ +from functools import reduce +import operator from urllib.parse import urlencode from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator +from django.db.models import Q from django.http import HttpResponseBadRequest from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse @@ -100,8 +103,28 @@ class ManageInviteRequests(View): if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: sort = "-created_date" + requests = models.InviteRequest.objects.filter(ignored=ignored).order_by(sort) + + status_filters = [ + s + for s in request.GET.getlist("status") + if s in ["requested", "sent", "accepted"] + ] + + filters = [] + if "requested" in status_filters: + filters.append({"invite__isnull": True}) + if "sent" in status_filters: + filters.append({"invite__isnull": False}) + if "accepted" in status_filters: + filters.append({"invite__isnull": False, "invite__times_used__gte": 1}) + + requests = requests.filter( + reduce(operator.or_, (Q(**f) for f in filters)) + ).distinct() + paginated = Paginator( - models.InviteRequest.objects.filter(ignored=ignored).order_by(sort), + requests, PAGE_LENGTH, ) From fc31b3e0b054cbba19e661986716ae30577fcec7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 14:22:01 -0700 Subject: [PATCH 4/4] Fixes invite requests page with no filters --- bookwyrm/views/invite.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/invite.py b/bookwyrm/views/invite.py index 0be48675e..665f98ce7 100644 --- a/bookwyrm/views/invite.py +++ b/bookwyrm/views/invite.py @@ -119,9 +119,10 @@ class ManageInviteRequests(View): if "accepted" in status_filters: filters.append({"invite__isnull": False, "invite__times_used__gte": 1}) - requests = requests.filter( - reduce(operator.or_, (Q(**f) for f in filters)) - ).distinct() + if filters: + requests = requests.filter( + reduce(operator.or_, (Q(**f) for f in filters)) + ).distinct() paginated = Paginator( requests,