def request_invitation(request):
    site = get_current_site(request)

    if request.method == 'POST':
        form = RequestInvitationForm(request.POST, request=request)

        if form.is_valid():

            # Create inactive user
            full_name = form.cleaned_data['full_name']
            email = form.cleaned_data['email']
            new_user = create_inactive_user(email, full_name)

            # Add additional details
            comments = form.cleaned_data['comments']
            new_user.registration_method = new_user.REQUESTED
            new_user.applied_datetime = now()
            new_user.application_comments = comments
            new_user.save()

            # Send email(s) to moderator(s) alerting them of new
            # account application
            moderators = User.objects.filter(is_moderator=True, is_active=True)

            url = request.build_absolute_uri(reverse(
                'moderation:review-applications'))

            subject = _('New account request at {}'.format(site.name))
            template = (
                'moderation/emails/notify_moderators_of_new_application.html'
            )

            for moderator in moderators:
                send_connect_email(subject=subject,
                                   template=template,
                                   recipient=moderator,
                                   site=site,
                                   url=url)

            return redirect('accounts:request-invitation-done')
    else:
        form = RequestInvitationForm(request=request)

    context = {
        'form': form,
    }

    return render(request, 'accounts/request_invitation.html', context)
Allow a member of the public to request an account invitation.
dataset/ETHPy150Open nlhkabu/connect/connect/accounts/views.py/request_invitation