当前位置: 首页>>代码示例>>Python>>正文


Python UserForm.non_field_errors方法代码示例

本文整理汇总了Python中payments.forms.UserForm.non_field_errors方法的典型用法代码示例。如果您正苦于以下问题:Python UserForm.non_field_errors方法的具体用法?Python UserForm.non_field_errors怎么用?Python UserForm.non_field_errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在payments.forms.UserForm的用法示例。


在下文中一共展示了UserForm.non_field_errors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_user

# 需要导入模块: from payments.forms import UserForm [as 别名]
# 或者: from payments.forms.UserForm import non_field_errors [as 别名]
def post_user(request):
    form = UserForm(request.DATA)

    print("in post user")
    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

        cd = form.cleaned_data
        try:
            with transaction.atomic():
                user = User.create(
                    cd['name'], cd['email'],
                    cd['password'], cd['last_4_digits'])

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()
        except IntegrityError as e:
            print("----------Integristy error")
            print(e)
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
开发者ID:Munk801,项目名称:book3-exercises,代码行数:45,代码来源:json_views.py


注:本文中的payments.forms.UserForm.non_field_errors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。