Invite creation improvements

This commit is contained in:
Andrew Godwin 2022-12-20 14:38:42 +00:00
parent 2fefd02e77
commit d1e398a7b7
2 changed files with 7 additions and 3 deletions

View File

@ -27,10 +27,11 @@ class Invite(models.Model):
admin_view = "{admin}{self.pk}/"
@classmethod
def create_random(cls, email=None):
def create_random(cls, email=None, note=None):
return cls.objects.create(
token="".join(
random.choice("abcdefghkmnpqrstuvwxyz23456789") for i in range(20)
),
email=email,
note=note,
)

View File

@ -43,8 +43,11 @@ class InviteCreate(FormView):
)
def form_valid(self, form):
invite = Invite.create_random(email=form.cleaned_data.get("email") or None)
return redirect(invite.urls.admin)
invite = Invite.create_random(
email=form.cleaned_data.get("email") or None,
note=form.cleaned_data.get("notes"),
)
return redirect(invite.urls.admin_view)
@method_decorator(moderator_required, name="dispatch")