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


Python Order.confirm方法代码示例

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


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

示例1: check_in

# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import confirm [as 别名]
def check_in(request):
    cart = Cart(request)
    template = "check/check_in.html"
    address_placeholders = dict(ADDRESS_PLACEHOLDERS)
    if request.method == "POST":
        form = CheckInForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            order = Order()
            order.surname = cd.get("surname")
            order.name = cd.get("name")
            order.pay_way = cd.get("pay_way")
            order.delivery_by = cd.get("delivery_by")
            order.phone = cd.get("phone")
            order.email = cd.get("email")
            order.address = cd.get("address")
            order.sum = cart.cart.total_sum
            order.comment = cd.get("user_comment")
            order.save()
            for item in cart:
                OrderItem(
                    order=order,
                    product=item.product,
                    product_name=item.product.name,
                    amount=item.quantity,
                    price=item.unit_price,
                    sum=item.total_price,
                ).save()
            # close cart
            if not can_proceed(order.confirm):
                raise PermissionDenied
            order.confirm()
            order.save()
            cart.cart.checked_out = True
            cart.cart.save()
            # save order data in session
            order_data = {
                ORDER_NAME: order.name,
                ORDER_SURNAME: order.surname,
                ORDER_PHONE: order.phone,
                ORDER_EMAIL: order.email,
                ORDER_ADDRESS: order.address,
            }
            request.session[ORDER_DATA] = order_data
            request.session[ORDER_ID] = order.pk
            to = reverse("cart-order-preview")
            if request.is_ajax():
                return JsonResponse({"success": True, "location": to})
            return redirect(to)
        else:
            if request.is_ajax():
                errors = dict([(k, force_text(v[0])) for k, v in form.errors.items()])
                return JsonResponse({"success": False, "errors": errors})
    else:
        order_data = request.session.get(ORDER_DATA)
        initial = {}
        if order_data:
            initial["surname"] = order_data.get(ORDER_SURNAME)
            initial["name"] = order_data.get(ORDER_NAME)
            initial["phone"] = order_data.get(ORDER_PHONE)
            initial["email"] = order_data.get(ORDER_EMAIL)
            initial["address"] = order_data.get(ORDER_ADDRESS)
        if initial:
            form = CheckInForm(initial=initial)
        else:
            form = CheckInForm()
        ctx = {"cart": cart, "form": form, "address_placeholders": address_placeholders}
        return render(request, template, ctx)
开发者ID:pombredanne,项目名称:minishop,代码行数:70,代码来源:views.py


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