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


Python Account.as_dict方法代码示例

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


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

示例1: checkout

# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import as_dict [as 别名]
def checkout(request, cart, order):
    """Handle checkout process - if the order is completed, show the success
       page, otherwise show the checkout form.
    """

    # if the cart is already linked with an order, show that order
    if not order and cart.order_obj:
        return redirect(cart.order_obj)

    if order and order.status >= Order.STATUS_PAID:
        if cart.order_obj == order:
            cart.clear()
        return {
            "template": "success",
            "order": order,
        }

    if request.user.is_authenticated():
        account = Account.objects.for_user(request.user)
        get_user_form = lambda *a: None
    else:
        account = Account()
        get_user_form = partial(CheckoutUserForm)

    if order:
        get_form = partial(OrderForm, instance=order)
        get_gift_form = partial(GiftRecipientForm, prefix='gift',
                                instance=order.get_gift_recipient())
        def sanity_check():
            return 0

        new_order = False
    else:
        # set initial data from the user's account, the shipping
        # options, and any saved session data
        initial = {}
        if account.pk and not initial:
            initial.update(account.as_dict())

        shipping_module = get_shipping_module()
        if shipping_module:
            initial.update(shipping_module.get_session(request))

        initial.update(request.session.get(CHECKOUT_SESSION_KEY, {}))

        get_form = partial(OrderForm, initial=initial)
        get_gift_form = partial(GiftRecipientForm, prefix='gift')
        sanity_check = lambda: cart.subtotal
        new_order = True

    # Add in any custom cart verification here
    cart_errors = []

    if request.method == 'POST':
        form = get_form(request.POST, sanity_check=sanity_check())

        user_form = get_user_form(request.POST)
        save_details = not account.pk and request.POST.get('save-details')
        if save_details and user_form:
            # if creating a new user, the email needs to be unused
            form.require_unique_email = True
            user_form_valid = user_form.is_valid()
        else:
            user_form_valid = True

        gift_form = get_gift_form(request.POST)
        is_gift = request.POST.get('is_gift')
        gift_form_valid = gift_form.is_valid() if is_gift else True

        if form.is_valid() and (order or not cart.empty()) and \
           user_form_valid and gift_form_valid and not len(cart_errors):
            # save the order obj to the db...
            order = form.save(commit=False)
            order.currency = cart.currency

            # save details to account if requested
            if save_details:
                account.from_obj(order)
                if user_form:
                    user = user_form.save(email=order.email, name=order.name)
                    account.user = user
                    auth_user = authenticate(
                        username=user.email,
                        password=user_form.cleaned_data['password1'])
                    login(request, auth_user)
                account.save()

            if account.pk:
                order.account = account

            order.save()

            if is_gift:
                recipient = gift_form.save(commit=False)
                recipient.order = order
                recipient.save()
            elif gift_form.instance and gift_form.instance.pk:
                gift_form.instance.delete()

            # save any cart lines to the order, overwriting existing lines, but
#.........这里部分代码省略.........
开发者ID:brendonjohn,项目名称:django-shoptools,代码行数:103,代码来源:views.py


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