コード例 #1
0
def validate_user(first_name: str, email: str, source: str) -> UserSignupForm:
    """
    Validate a user
    :param first_name:
    :param email:
    :param source:
    :return:
    """
    data = {'first_name': first_name, 'email': email, 'source': source}

    form = UserSignupForm(data)
    if not form.is_valid():
        raise UserCreationException(form)
    return form
コード例 #2
0
ファイル: views.py プロジェクト: moacirmoda/pythonpro-website
def lead_form(request):
    if request.method == 'GET':
        form = UserSignupForm()
        return render(request,
                      'core/lead_form_errors.html',
                      context={'form': form})
    form = UserSignupForm(request.POST)
    if form.is_valid():
        user = form.save()
        assign_role(user, 'lead')
        facade.create_or_update_lead(user.first_name, user.email)
        return redirect(reverse('core:thanks'))
    return render(request,
                  'core/lead_form_errors.html',
                  context={'form': form})