Placeholders for send/ignore request flows

This commit is contained in:
Mouse Reeve 2021-03-20 20:15:50 -07:00
parent f91a8144f4
commit 5e24b438ff
7 changed files with 87 additions and 61 deletions

View file

@ -1,58 +0,0 @@
# Generated by Django 3.1.6 on 2021-03-21 01:23
import bookwyrm.models.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0055_auto_20210321_0101"),
]
operations = [
migrations.AddField(
model_name="sitesettings",
name="allow_invite_requests",
field=models.BooleanField(default=True),
),
migrations.CreateModel(
name="InviteRequest",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("updated_date", models.DateTimeField(auto_now=True)),
(
"remote_id",
bookwyrm.models.fields.RemoteIdField(
max_length=255,
null=True,
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
("email", models.EmailField(max_length=255, unique=True)),
("invite_sent", models.BooleanField(default=False)),
(
"invite",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="bookwyrm.siteinvite",
),
),
],
options={
"abstract": False,
},
),
]

View file

@ -0,0 +1,36 @@
# Generated by Django 3.1.6 on 2021-03-21 03:03
import bookwyrm.models.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0055_auto_20210321_0101'),
]
operations = [
migrations.AddField(
model_name='sitesettings',
name='allow_invite_requests',
field=models.BooleanField(default=True),
),
migrations.CreateModel(
name='InviteRequest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_date', models.DateTimeField(auto_now_add=True)),
('updated_date', models.DateTimeField(auto_now=True)),
('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])),
('email', models.EmailField(max_length=255, unique=True)),
('invite_sent', models.BooleanField(default=False)),
('ignored', models.BooleanField(default=False)),
('invite', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='bookwyrm.siteinvite')),
],
options={
'abstract': False,
},
),
]

View file

@ -79,6 +79,7 @@ class InviteRequest(BookWyrmModel):
SiteInvite, on_delete=models.SET_NULL, null=True, blank=True
)
invite_sent = models.BooleanField(default=False)
ignored = models.BooleanField(default=False)
def save(self, *args, **kwargs):
""" don't create a request for a registered email """

View file

@ -25,6 +25,7 @@
<th>{% trans "Date" %}</th>
<th>{% trans "Email" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Action" %}</th>
</tr>
{% if not requests %}
<tr><td colspan="4">{% trans "No requests" %}</td></tr>
@ -33,7 +34,33 @@
<tr>
<td>{{ req.created_date | naturaltime }}</td>
<td>{{ req.email }}</td>
<td>{% trans "Pending" %}</td>
<td>
{% if req.invite.times_used %}
{% trans "Accepted" %}
{% elif req.invite %}
{% trans "Sent" %}
{% else %}
{% trans "Requested" %}
{% endif %}
</td>
<td>
{% if req.invite and not req.invite.times_used %}
<button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button>
{% else %}
<div class="field is-grouped">
<form name="send-invite" method="post" action="{% url 'settings-invite-requests' %}">
{% csrf_token %}
<input type="hidden" name="invite-request" value="{{ req.id }}">
<button type="submit" class="button is-link is-light is-small">{% trans "Send invite" %}</button>
</form>
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">
<input type="hidden" name="invite-request" value="{{ req.id }}">
<button type="submit" class="button is-danger is-light is-small">{% trans "Ignore" %}</button>
</form>
</div>
{% endif %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -59,6 +59,11 @@ urlpatterns = [
views.ManageInviteRequests.as_view(),
name="settings-invite-requests",
),
re_path(
r"^settings/requests/ignore?$",
views.ignore_invite_request,
name="settings-invite-requests-ignore",
),
re_path(
r"^invite-request/?$", views.InviteRequest.as_view(), name="invite-request"
),

View file

@ -13,7 +13,8 @@ from .goal import Goal, hide_goal
from .import_data import Import, ImportStatus
from .inbox import Inbox
from .interaction import Favorite, Unfavorite, Boost, Unboost
from .invite import ManageInvites, Invite, InviteRequest, ManageInviteRequests
from .invite import ManageInvites, Invite, InviteRequest
from .invite import ManageInviteRequests, ignore_invite_request
from .isbn import Isbn
from .landing import About, Home, Discover
from .list import Lists, List, Curate, UserLists

View file

@ -6,6 +6,7 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.http import require_POST
from bookwyrm import forms, models
from bookwyrm.settings import PAGE_LENGTH
@ -85,21 +86,29 @@ class ManageInviteRequests(View):
def get(self, request):
""" view a list of requests """
ignored = request.GET.get("ignored", False)
try:
page = int(request.GET.get("page", 1))
except ValueError:
page = 1
paginated = Paginator(
models.InviteRequest.objects.all().order_by("-created_date"),
models.InviteRequest.objects.filter(
ignored=ignored
).order_by("-created_date"),
PAGE_LENGTH,
)
data = {
"ignored": ignored,
"requests": paginated.page(page),
}
return TemplateResponse(request, "settings/manage_invite_requests.html", data)
def post(self, request):
""" send out an invite """
class InviteRequest(View):
""" prospective users sign up here """
@ -118,3 +127,8 @@ class InviteRequest(View):
"books": helpers.get_discover_books(),
}
return TemplateResponse(request, "discover/discover.html", data)
@require_POST
def ignore_invite_request(request):
""" ok """