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}/" admin_view = "{admin}{self.pk}/"
@classmethod @classmethod
def create_random(cls, email=None): def create_random(cls, email=None, note=None):
return cls.objects.create( return cls.objects.create(
token="".join( token="".join(
random.choice("abcdefghkmnpqrstuvwxyz23456789") for i in range(20) random.choice("abcdefghkmnpqrstuvwxyz23456789") for i in range(20)
), ),
email=email, email=email,
note=note,
) )

View file

@ -43,8 +43,11 @@ class InviteCreate(FormView):
) )
def form_valid(self, form): def form_valid(self, form):
invite = Invite.create_random(email=form.cleaned_data.get("email") or None) invite = Invite.create_random(
return redirect(invite.urls.admin) 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") @method_decorator(moderator_required, name="dispatch")