本文整理汇总了Python中payments.forms.CardForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python CardForm.is_valid方法的具体用法?Python CardForm.is_valid怎么用?Python CardForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类payments.forms.CardForm
的用法示例。
在下文中一共展示了CardForm.is_valid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from payments.forms import CardForm [as 别名]
# 或者: from payments.forms.CardForm import is_valid [as 别名]
def edit(request):
uid = request.session.get('user')
if uid is None:
return HttpResponseRedirect('/')
user = User.objects.get(pk=uid)
if request.method == 'POST':
form = CardForm(request.POST)
if form.is_valid():
customer = stripe.Customer.retrieve(user.stripe_id)
customer.card = form.cleaned_data['stripe_token']
customer.save()
user.last_4_digits = form.cleaned_data['last_4_digits']
user.stripe_id = customer.id
user.save()
return HttpResponseRedirect('/')
else:
form = CardForm()
return render_to_response(
'edit.html', {
'form': form,
'publishable': settings.STRIPE_PUBLISHABLE,
'soon': soon(),
'months': range(1, 12),
'years': range(2011, 2036)
},
context_instance=RequestContext(request))
示例2: select_payment
# 需要导入模块: from payments.forms import CardForm [as 别名]
# 或者: from payments.forms.CardForm import is_valid [as 别名]
def select_payment(request, auction_id):
session_card = 'auction_%s_payment' % auction_id
# session_shipping = 'auction_%s_shipping' % auction_id
member = request.user.get_profile()
auction = get_object_or_404(request.user.items_won.filter(order=None), id=auction_id)
cards = request.user.card_set.filter(deleted=False)
id = request.POST.get('card')
# action = request.POST.get('action')
card = None
if 'select' in request.POST:
card = get_object_or_404(Card, id=id, user=request.user, deleted=False)
request.session[session_card] = card.id
return HttpResponseRedirect(reverse('checkout_review', args=[auction.id]))
if request.method == 'POST':
form = CardForm(request.POST)
if form.is_valid():
# data = form.cleaned_data
card = form.save(commit=False)
card.use = request.user
card.save()
request.session[session_card] = card.id
cards = request.user.card_set.filter(deleted=False)
form = CardForm()
else:
form = CardForm()
return {
'auction':auction,
'form':form,
'cards':cards,
'card':card
}
示例3: edit
# 需要导入模块: from payments.forms import CardForm [as 别名]
# 或者: from payments.forms.CardForm import is_valid [as 别名]
def edit(request):
uid = request.session.get("user")
if uid is None:
return HttpResponseRedirect("/")
user = User.objects.get(pk=uid)
if request.method == "POST":
form = CardForm(request.POST)
if form.is_valid():
customer = stripe.Customer.retrieve(user.stripe_id)
customer.card = form.cleaned_data["stripe_token"]
customer.save()
user.last_4_digits = form.cleaned_data["last_4_digits"]
user.stripe_id = customer.id
user.save()
return HttpResponseRedirect("/")
else:
form = CardForm()
return render_to_response(
"payments/edit.html",
{
"form": form,
"publishable": settings.STRIPE_PUBLISHABLE,
"soon": soon(),
"months": list(range(1, 12)),
"years": list(range(2011, 2036)),
},
context_instance=RequestContext(request),
)
示例4: manage_payments
# 需要导入模块: from payments.forms import CardForm [as 别名]
# 或者: from payments.forms.CardForm import is_valid [as 别名]
def manage_payments(request, redirect_url='profile_account'):
objects = request.user.card_set.filter(deleted=False)
form = CardForm(request.POST or None)
if form.is_valid():
instance = form.save(commit=False)
instance.user = request.user
instance.save()
return HttpResponseRedirect(reverse('profile_account'))
return {
'form':form,
'cards':objects,
}