mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-29 10:40:59 +00:00
Invites admin
This commit is contained in:
parent
84dbb51de7
commit
0c4eb74165
8 changed files with 185 additions and 22 deletions
|
@ -377,8 +377,8 @@ img.emoji {
|
||||||
color: var(--color-text-dull);
|
color: var(--color-text-dull);
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-menu .option.empty:hover {
|
.icon-menu .option.empty:hover,
|
||||||
border: 0;
|
.icon-menu .option.static:hover {
|
||||||
border: 2px solid rgba(255, 255, 255, 0);
|
border: 2px solid rgba(255, 255, 255, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,6 +1096,7 @@ table.metadata td .emoji {
|
||||||
font-weight: lighter;
|
font-weight: lighter;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post .poll ul {
|
.post .poll ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
@ -1104,14 +1105,17 @@ table.metadata td .emoji {
|
||||||
padding: 6px 0;
|
padding: 6px 0;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.poll-number {
|
.poll-number {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 45px;
|
width: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.poll-footer {
|
.poll-footer {
|
||||||
padding: 6px 0 6px;
|
padding: 6px 0 6px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post .poll ul li .votes {
|
.post .poll ul li .votes {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
|
|
|
@ -127,9 +127,19 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"admin/invites/",
|
"admin/invites/",
|
||||||
admin.Invites.as_view(),
|
admin.InvitesRoot.as_view(),
|
||||||
name="admin_invites",
|
name="admin_invites",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"admin/invites/create/",
|
||||||
|
admin.InviteCreate.as_view(),
|
||||||
|
name="admin_invite_create",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"admin/invites/<id>/",
|
||||||
|
admin.InviteView.as_view(),
|
||||||
|
name="admin_invite_view",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"admin/hashtags/",
|
"admin/hashtags/",
|
||||||
admin.Hashtags.as_view(),
|
admin.Hashtags.as_view(),
|
||||||
|
|
18
templates/admin/invite_create.html
Normal file
18
templates/admin/invite_create.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "settings/base.html" %}
|
||||||
|
|
||||||
|
{% block subtitle %}Create Invite{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="." method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset>
|
||||||
|
<legend>Details</legend>
|
||||||
|
{% include "forms/_field.html" with field=form.email %}
|
||||||
|
{% include "forms/_field.html" with field=form.notes %}
|
||||||
|
</fieldset>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="{% url "admin_invites" %}" class="button secondary left">Back</a>
|
||||||
|
<button>Create</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
20
templates/admin/invite_view.html
Normal file
20
templates/admin/invite_view.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends "settings/base.html" %}
|
||||||
|
|
||||||
|
{% block subtitle %}View Invite{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="." method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset>
|
||||||
|
<legend>Details</legend>
|
||||||
|
{% include "forms/_field.html" with field=form.code %}
|
||||||
|
{% include "forms/_field.html" with field=form.email %}
|
||||||
|
{% include "forms/_field.html" with field=form.notes %}
|
||||||
|
</fieldset>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="{% url "admin_invites" %}" class="button secondary left">Back</a>
|
||||||
|
<button class="delete" name="delete">Delete</button>
|
||||||
|
<button>Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -1,9 +1,41 @@
|
||||||
{% extends "settings/base.html" %}
|
{% extends "settings/base.html" %}
|
||||||
|
{% load activity_tags %}
|
||||||
|
|
||||||
{% block subtitle %}Invites{% endblock %}
|
{% block subtitle %}Invites{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p>
|
<form>
|
||||||
Please use the <a href="/djadmin/users/invite/">Django Admin</a> for now.
|
<div class="buttons">
|
||||||
|
<a href="{% url "admin_invite_create" %}" class="button">Create New</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<section class="icon-menu">
|
||||||
|
{% for invite in page_obj %}
|
||||||
|
<a class="option" href="{{ invite.urls.admin_view }}">
|
||||||
|
<i class="fa-solid fa-envelope"></i>
|
||||||
|
<span class="handle">
|
||||||
|
{{ invite.token }}
|
||||||
|
|
||||||
|
<small>
|
||||||
|
{% if invite.email %}
|
||||||
|
(email {{ invite.email }})
|
||||||
|
{% endif %}
|
||||||
|
</small>
|
||||||
|
</span>
|
||||||
|
<time>{{ invite.created|timedeltashort }} ago</time>
|
||||||
|
</a>
|
||||||
|
{% empty %}
|
||||||
|
<p class="option empty">
|
||||||
|
There are no unused invites.
|
||||||
</p>
|
</p>
|
||||||
|
{% endfor %}
|
||||||
|
<div class="load-more">
|
||||||
|
{% if page_obj.has_previous %}
|
||||||
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
import urlman
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +21,11 @@ class Invite(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
updated = models.DateTimeField(auto_now=True)
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
class urls(urlman.Urls):
|
||||||
|
admin = "/admin/invites/"
|
||||||
|
admin_create = "{admin}create/"
|
||||||
|
admin_view = "{admin}{self.pk}/"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_random(cls, email=None):
|
def create_random(cls, email=None):
|
||||||
return cls.objects.create(
|
return cls.objects.create(
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django import forms
|
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import FormView, RedirectView
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
from users.decorators import admin_required
|
from users.decorators import admin_required
|
||||||
from users.views.admin.domains import ( # noqa
|
from users.views.admin.domains import ( # noqa
|
||||||
|
@ -17,6 +16,7 @@ from users.views.admin.hashtags import ( # noqa
|
||||||
Hashtags,
|
Hashtags,
|
||||||
)
|
)
|
||||||
from users.views.admin.identities import IdentitiesRoot, IdentityEdit # noqa
|
from users.views.admin.identities import IdentitiesRoot, IdentityEdit # noqa
|
||||||
|
from users.views.admin.invites import InviteCreate, InvitesRoot, InviteView # noqa
|
||||||
from users.views.admin.reports import ReportsRoot, ReportView # noqa
|
from users.views.admin.reports import ReportsRoot, ReportView # noqa
|
||||||
from users.views.admin.settings import ( # noqa
|
from users.views.admin.settings import ( # noqa
|
||||||
BasicSettings,
|
BasicSettings,
|
||||||
|
@ -30,17 +30,3 @@ from users.views.admin.users import UserEdit, UsersRoot # noqa
|
||||||
@method_decorator(admin_required, name="dispatch")
|
@method_decorator(admin_required, name="dispatch")
|
||||||
class AdminRoot(RedirectView):
|
class AdminRoot(RedirectView):
|
||||||
pattern_name = "admin_basic"
|
pattern_name = "admin_basic"
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(admin_required, name="dispatch")
|
|
||||||
class Invites(FormView):
|
|
||||||
|
|
||||||
template_name = "admin/invites.html"
|
|
||||||
extra_context = {"section": "invites"}
|
|
||||||
|
|
||||||
class form_class(forms.Form):
|
|
||||||
note = forms.CharField()
|
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
|
||||||
context = super().get_context_data(*args, **kwargs)
|
|
||||||
return context
|
|
||||||
|
|
87
users/views/admin/invites.py
Normal file
87
users/views/admin/invites.py
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
from django import forms
|
||||||
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.generic import FormView, ListView
|
||||||
|
|
||||||
|
from users.decorators import admin_required
|
||||||
|
from users.models import Invite
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
class InvitesRoot(ListView):
|
||||||
|
|
||||||
|
template_name = "admin/invites.html"
|
||||||
|
paginate_by = 30
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
self.extra_context = {
|
||||||
|
"section": "invites",
|
||||||
|
}
|
||||||
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Invite.objects.order_by("created")
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
class InviteCreate(FormView):
|
||||||
|
|
||||||
|
template_name = "admin/invite_create.html"
|
||||||
|
extra_context = {
|
||||||
|
"section": "invites",
|
||||||
|
}
|
||||||
|
|
||||||
|
class form_class(forms.Form):
|
||||||
|
email = forms.EmailField(
|
||||||
|
required=False,
|
||||||
|
help_text="Optional email to tie the invite to.\nYou will still need to email the user this code yourself!",
|
||||||
|
)
|
||||||
|
notes = forms.CharField(
|
||||||
|
required=False,
|
||||||
|
widget=forms.Textarea,
|
||||||
|
help_text="Notes for other admins",
|
||||||
|
)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
invite = Invite.create_random(email=form.cleaned_data.get("email") or None)
|
||||||
|
return redirect(invite.urls.admin)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
class InviteView(FormView):
|
||||||
|
|
||||||
|
template_name = "admin/invite_view.html"
|
||||||
|
extra_context = {
|
||||||
|
"section": "invites",
|
||||||
|
}
|
||||||
|
|
||||||
|
class form_class(InviteCreate.form_class):
|
||||||
|
code = forms.CharField(disabled=True, required=False)
|
||||||
|
|
||||||
|
def dispatch(self, request, id, *args, **kwargs):
|
||||||
|
self.invite = get_object_or_404(Invite, id=id)
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
if "delete" in request.POST:
|
||||||
|
self.invite.delete()
|
||||||
|
return redirect(self.invite.urls.admin)
|
||||||
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
return {
|
||||||
|
"notes": self.invite.note,
|
||||||
|
"email": self.invite.email,
|
||||||
|
"code": self.invite.token,
|
||||||
|
}
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
self.invite.note = form.cleaned_data.get("notes") or ""
|
||||||
|
self.invite.email = form.cleaned_data.get("email") or None
|
||||||
|
self.invite.save()
|
||||||
|
return redirect(self.invite.urls.admin)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["invite"] = self.invite
|
||||||
|
return context
|
Loading…
Reference in a new issue