Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-04-01 14:32:21 -07:00
commit 01f598a951
2 changed files with 51 additions and 7 deletions

View file

@ -26,11 +26,20 @@
{% endif %} ({{ count }})
</h2>
{% include 'settings/invite_request_filters.html' %}
<table class="table is-striped">
{% url 'settings-invite-requests' as url %}
<tr>
<th>{% trans "Date" %}</th>
<th>
{% trans "Date" as text %}
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
</th>
<th>{% trans "Email" %}</th>
<th>{% trans "Status" %}</th>
<th>
{% trans "Status" as text %}
{% include 'snippets/table-sort-header.html' with field="invite__times_used" sort=sort text=text %}
</th>
<th>{% trans "Action" %}</th>
</tr>
{% if not requests %}
@ -50,7 +59,7 @@
{% endif %}
</td>
<td class="field is-grouped">
<form name="send-invite" method="post" action="{% url 'settings-invite-requests' %}">
<form name="send-invite" method="post">
{% csrf_token %}
<input type="hidden" name="invite-request" value="{{ req.id }}">
{% if not req.invite %}

View file

@ -1,9 +1,15 @@
""" 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
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
@ -92,10 +98,34 @@ 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"
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})
if filters:
requests = requests.filter(
reduce(operator.or_, (Q(**f) for f in filters))
).distinct()
paginated = Paginator(
models.InviteRequest.objects.filter(ignored=ignored).order_by(
"-created_date"
),
requests,
PAGE_LENGTH,
)
@ -103,6 +133,7 @@ class ManageInviteRequests(View):
"ignored": ignored,
"count": paginated.count,
"requests": paginated.page(page),
"sort": sort,
}
return TemplateResponse(request, "settings/manage_invite_requests.html", data)
@ -119,7 +150,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):