forked from mirrors/bookwyrm
Merge pull request #642 from mouse-reeve/invite-pagination
Invite pagination
This commit is contained in:
commit
0d68d22f73
2 changed files with 44 additions and 25 deletions
|
@ -2,28 +2,6 @@
|
||||||
{% block header %}Invites{% endblock %}
|
{% block header %}Invites{% endblock %}
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
<section class="block">
|
|
||||||
<table class="table is-striped">
|
|
||||||
<tr>
|
|
||||||
<th>Link</th>
|
|
||||||
<th>Expires</th>
|
|
||||||
<th>Max uses</th>
|
|
||||||
<th>Times used</th>
|
|
||||||
</tr>
|
|
||||||
{% if not invites %}
|
|
||||||
<tr><td colspan="4">No active invites</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
{% for invite in invites %}
|
|
||||||
<tr>
|
|
||||||
<td><a href="{{ invite.link }}">{{ invite.link }}</td>
|
|
||||||
<td>{{ invite.expiry|naturaltime }}</td>
|
|
||||||
<td>{{ invite.use_limit }}</td>
|
|
||||||
<td>{{ invite.times_used }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="block">
|
<section class="block">
|
||||||
<h2 class="title is-4">Generate New Invite</h2>
|
<h2 class="title is-4">Generate New Invite</h2>
|
||||||
|
|
||||||
|
@ -47,4 +25,27 @@
|
||||||
<button class="button is-primary" type="submit">Create Invite</button>
|
<button class="button is-primary" type="submit">Create Invite</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="block">
|
||||||
|
<table class="table is-striped">
|
||||||
|
<tr>
|
||||||
|
<th>Link</th>
|
||||||
|
<th>Expires</th>
|
||||||
|
<th>Max uses</th>
|
||||||
|
<th>Times used</th>
|
||||||
|
</tr>
|
||||||
|
{% if not invites %}
|
||||||
|
<tr><td colspan="4">No active invites</td></tr>
|
||||||
|
{% endif %}
|
||||||
|
{% for invite in invites %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ invite.link }}">{{ invite.link }}</td>
|
||||||
|
<td>{{ invite.expiry|naturaltime }}</td>
|
||||||
|
<td>{{ invite.use_limit }}</td>
|
||||||
|
<td>{{ invite.times_used }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% include 'snippets/pagination.html' with page=invites path=request.path %}
|
||||||
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
''' invites when registration is closed '''
|
''' invites when registration is closed '''
|
||||||
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.http import HttpResponseBadRequest
|
from django.http import HttpResponseBadRequest
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -7,6 +8,7 @@ from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
|
@ -18,10 +20,18 @@ class ManageInvites(View):
|
||||||
''' create invites '''
|
''' create invites '''
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
''' invite management page '''
|
''' 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 = {
|
data = {
|
||||||
'title': 'Invitations',
|
'title': 'Invitations',
|
||||||
'invites': models.SiteInvite.objects.filter(
|
'invites': paginated.page(page),
|
||||||
user=request.user).order_by('-created_date'),
|
|
||||||
'form': forms.CreateInviteForm(),
|
'form': forms.CreateInviteForm(),
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'settings/manage_invites.html', data)
|
return TemplateResponse(request, 'settings/manage_invites.html', data)
|
||||||
|
@ -36,7 +46,15 @@ class ManageInvites(View):
|
||||||
invite.user = request.user
|
invite.user = request.user
|
||||||
invite.save()
|
invite.save()
|
||||||
|
|
||||||
return redirect('/settings/invites')
|
paginated = Paginator(models.SiteInvite.objects.filter(
|
||||||
|
user=request.user
|
||||||
|
).order_by('-created_date'), PAGE_LENGTH)
|
||||||
|
data = {
|
||||||
|
'title': 'Invitations',
|
||||||
|
'invites': paginated.page(1),
|
||||||
|
'form': form
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'settings/manage_invites.html', data)
|
||||||
|
|
||||||
|
|
||||||
class Invite(View):
|
class Invite(View):
|
||||||
|
|
Loading…
Reference in a new issue