mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
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 %}
|
||||
{% load humanize %}
|
||||
{% 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">
|
||||
<h2 class="title is-4">Generate New Invite</h2>
|
||||
|
||||
|
@ -47,4 +25,27 @@
|
|||
<button class="button is-primary" type="submit">Create Invite</button>
|
||||
</form>
|
||||
</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 %}
|
||||
|
|
|
@ -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)
|
||||
|
@ -36,7 +46,15 @@ class ManageInvites(View):
|
|||
invite.user = request.user
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue