當前位置: 首頁>>代碼示例>>Python>>正文


Python Order.email方法代碼示例

本文整理匯總了Python中orders.models.Order.email方法的典型用法代碼示例。如果您正苦於以下問題:Python Order.email方法的具體用法?Python Order.email怎麽用?Python Order.email使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在orders.models.Order的用法示例。


在下文中一共展示了Order.email方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_in

# 需要導入模塊: from orders.models import Order [as 別名]
# 或者: from orders.models.Order import email [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

示例2: process_order

# 需要導入模塊: from orders.models import Order [as 別名]
# 或者: from orders.models.Order import email [as 別名]
    def process_order(self, pyOrder, payment_form):
        """
        Takes the following steps:
        1.  Locks the products in the cart, read-only access only (TBD, I have no idea how to do this ATM)
        2.  Creates an Order instance from the form data in this checkout process, and validates it (it should checkout
            ok, if it doesn't there was a bug in my forms.
        3.  Authorize credit-card, payment information  (the payment form will have a hidden containing the amount to
            put on the card.  This way the number the user sees and the number I charge are guaranteed to be the same.
        4.  Submit the order (save it)
        5.  Decrement product stock
        6.  Unlock the products that were locked in step 1
        7.  Redirect the user to a receipt page
        """
        order = Order()               # db class

        if not payment_form.is_valid():
            return False

        # link user information, even if that user is a guest (lazy) account.  They'll need this information set in
        # order to view their order receipt at the end of the process.
        order.user = self.request.user
        order.first_name = pyOrder.first_name
        order.last_name = pyOrder.last_name
        order.email = pyOrder.email
        order.phone = pyOrder.phone
        order.contact_method = pyOrder.contact_method

        order.shipping_method = pyOrder.shipping_method
        order.shipping_charge = pyOrder.shipping_charge
        order.save()

        # save the payment information
        payment_form.save(order)

        shipping_address = pyOrder.shipping_address.as_address(OrderShippingAddress)
        shipping_address.order = order
        shipping_address.save()

        billing_address = pyOrder.billing_address.as_address(OrderBillingAddress)
        billing_address.order = order
        billing_address.save()

        for order_item in pyOrder.items:
            order_item.order = order
            order_item.full_clean()
            order_item.save()

            # decrement stock for products
            if order_item.is_product():
                in_stock = order_item.item.quantity
                order_item.item.quantity = max(0, in_stock - order_item.quantity)
                order_item.item.save()

            # mark wish list items as sold
            wishlist_links = order_item.cart_item.wishlist_links.all()
            for link in wishlist_links:
                link.wishlist_item.order_item = order_item
                link.wishlist_item.full_clean()
                link.wishlist_item.save()

        for (name, rate, total) in pyOrder.tax_breakdown():
            orderTax = OrderTax(name=name, rate=rate, total=total, order=order)
            orderTax.save()

        # save the order-id in the session dictionary
        self.save('order', order.id)
        return True
開發者ID:arthurcode,項目名稱:arthurcode,代碼行數:69,代碼來源:views.py


注:本文中的orders.models.Order.email方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。