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


Python CardForm.is_valid方法代码示例

本文整理汇总了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))
开发者ID:mvo1989,项目名称:book2-exercises,代码行数:36,代码来源:views.py

示例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
    }
开发者ID:SocialShoppingNetwork,项目名称:Competitive-Social-Shopping-Django,代码行数:37,代码来源:views.py

示例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),
    )
开发者ID:joelstanner,项目名称:realpython---django-mvp,代码行数:37,代码来源:views.py

示例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,
    }
开发者ID:SocialShoppingNetwork,项目名称:Competitive-Social-Shopping-Django,代码行数:15,代码来源:views.py


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