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


Python Request.note方法代碼示例

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


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

示例1: placeorder

# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import note [as 別名]
def placeorder():

    cart_items = Cart.query.filter_by(user_id=current_user.id).all()

    form = ShopOrderConfirmForm()
    if form.validate_on_submit():
        new_request = Request()
        new_request.user_id = current_user.id
        if not current_user.customer:
            flash(gettext("We apologize but your customer data is insufficient. Please, contact our customer support."))
            return redirect(url_for("shop"))

        customer_note = form.note.data
        if customer_note:
            new_request.note = customer_note

        new_request.customer_id = current_user.customer.id
        new_request.active_flg = True
        db.session.add(new_request)
        db.session.commit()

        for item in cart_items:
            new_product = db.session.query(Product).filter_by(id=item.product_id).first()
            if not new_product:
                flash(gettext("Product not found."))
                return redirect(url_for("shop"))
            rp = RequestedProducts(quantity=item.quantity)
            rp.product = new_product
            rp.request_id = new_request.id
            new_request.products.append(rp)
            db.session.delete(item)

        db.session.commit()

        # send confirmation email
        mailer.order_confirmation(current_user, new_request)

        flash(gettext("Order created successfully."))
        return redirect(url_for("orderconfirm", req_id=new_request.id))

    discount = 0
    if current_user.role == USER_ROLES['ROLE_CUSTOMER'] and current_user.customer:
        discount = current_user.customer.base_discount
    total = 0
    pieces = 0
    for item in cart_items:
        if not item.product.price_retail:
            item.product.price_retail = 0
        unrounded_price = item.product.price_retail * (1.0 - discount)
        item.customer_price = int(5 * round(float(unrounded_price)/5))
        total += item.customer_price * item.quantity
        pieces += item.quantity

        urls = getImgUrls(item.product.id)
        if urls:
            item.img_url = urls[0].split('app')[1]
        else:
            item.img_url = NO_PHOTO_URL.split('app')[1]

    return render_template('/shop/placeorder.html',
                           title=gettext('Place order'),
                           cart_items=cart_items,
                           total=total,
                           pieces=pieces,
                           form=form)
開發者ID:,項目名稱:,代碼行數:67,代碼來源:


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