本文整理汇总了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)