Paginates invite page

I sure have sent out a lot of invites
This commit is contained in:
Mouse Reeve 2021-02-23 14:41:33 -08:00
parent 5472281f29
commit d3381d7a79
2 changed files with 13 additions and 2 deletions

View file

@ -22,6 +22,7 @@
</tr>
{% endfor %}
</table>
{% include 'snippets/pagination.html' with page=invites path=request.path %}
</section>
<section class="block">

View file

@ -1,5 +1,6 @@
''' invites when registration is closed '''
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
@ -7,6 +8,7 @@ from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
from bookwyrm.settings import PAGE_LENGTH
# pylint: disable= no-self-use
@ -18,10 +20,18 @@ class ManageInvites(View):
''' create invites '''
def get(self, request):
''' invite management page '''
try:
page = int(request.GET.get('page', 1))
except ValueError:
page = 1
paginated = Paginator(models.SiteInvite.objects.filter(
user=request.user
).order_by('-created_date'), PAGE_LENGTH)
data = {
'title': 'Invitations',
'invites': models.SiteInvite.objects.filter(
user=request.user).order_by('-created_date'),
'invites': paginated.page(page),
'form': forms.CreateInviteForm(),
}
return TemplateResponse(request, 'settings/manage_invites.html', data)