def invite(request): """Invite a user.""" if request.POST: form = forms.InviteUserForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] user = User.objects.create_user(username=USERNAME_ALGO(email), email=email) user.userprofile.added_by = request.user user.userprofile.save() messages.success(request, ('User was successfully invited, ' 'now shoot some mails!')) return redirect('profiles_invite') else: form = forms.InviteUserForm() return render(request, 'profiles_invite.html', {'form': form})
def invite(request): """Invite a user.""" form = forms.InviteUserForm(request.POST or None) if form.is_valid(): email = form.cleaned_data['email'] user = User.objects.create_user(username=USERNAME_ALGO(email), email=email) # Add new users to Rep group user.groups.add(Group.objects.get(name='Rep')) user.userprofile.added_by = request.user user.userprofile.save() messages.success(request, ('User was successfully invited, ' 'now shoot some mails!')) return redirect('profiles_invite') return render(request, 'profiles_invite.jinja', {'form': form})