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


Python Request.active_flg方法代码示例

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


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

示例1: createRequest

# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import active_flg [as 别名]
def createRequest():
    cust = flask.request.args.get('cust')
    if not cust:
        cust = 'cust'
    if cust == 'cust':
        formCustomer = SelectCustomerForm()
        cust_customers = Customer.query.filter_by(customer_type=CUSTOMER_TYPES['TYPE_CUSTOMER']).all()
        cust_customers = [(a.id, a.name) for a in cust_customers]
        cust_customers = [(0, '')] + cust_customers
        formCustomer.customer.choices = cust_customers
    else:
        formCustomer = OrderNumberForm()
    makers = Maker.query.all()
    maker_choices = [(a.id, a.name) for a in makers]
    maker_choices = [(0, '')] + maker_choices
    formCustomer.maker.choices = maker_choices
    if formCustomer.is_submitted():
        ids = {}
        for attr in flask.request.form:
            if attr.startswith("req_qty-"):
                key = attr.split('-')[1]
                ids[key] = flask.request.form[attr]
        if ids:
            if cust == 'cust':
                cust_id = int(formCustomer.customer.data)
                if not cust_id:
                    flash(gettext("No customer id."))
                    return redirect(url_for("requests"))
                req_cust = db.session.query(Customer).filter_by(id=cust_id).first()
                if not req_cust:
                    flash(gettext("Customer not found."))
                    return redirect(url_for("requests"))
                if req_cust.customer_type != CUSTOMER_TYPES['TYPE_CUSTOMER']:
                    flash(gettext("Invalid customer!"))
                    return redirect(url_for("requests"))

            elif cust == 'axm':
                order_no = formCustomer.order_no.data
                if not order_no:
                    flash(gettext("No order number."))
                    return redirect(url_for("axm_requests"))
                req_cust = db.session.query(Customer).filter_by(order_no=order_no).first()
                if req_cust:
                    flash(gettext("Order number already exists!"))
                    return redirect(url_for("axm_requests"))
                req_cust = Customer()
                req_cust.customer_type = CUSTOMER_TYPES['TYPE_AXM']
                req_cust.order_no = order_no
                db.session.add(req_cust)
                db.session.commit()
            else:
                flash(gettext("Invalid data received!"))
                return redirect(url_for("requests"))

            new_request = Request()
            new_request.user_id = g.user.id
            new_request.customer_id = req_cust.id
            if formCustomer.datetime.data:
                new_request.created_dt = formCustomer.datetime.data
            else:
                flash("Date and time date of request was entered incorrectly, request saved with current date and time.")

            if cust == 'axm':
                if formCustomer.payment_method.data is not None:
                    new_request.payment_method = formCustomer.payment_method.data
                else:
                    new_request.payment_method = 1
                if formCustomer.paid_for_flg is not None:
                    new_request.paid_for_flg = formCustomer.paid_for_flg.data
                else:
                    new_request.paid_for_flg = 0

            new_request.active_flg = True
            db.session.add(new_request)
            db.session.commit()

            for id in ids:
                new_product = db.session.query(Product).filter_by(id=id).first()
                if not new_product:
                    flash(gettext("Product not found."))
                    return redirect(url_for("requests"))
                rp = RequestedProducts(quantity=int(ids[id]))
                rp.product = new_product
                rp.request_id = new_request.id
                new_request.products.append(rp)

            db.session.commit()
            flash(gettext("Order created successfully."))
            if cust == 'axm':
                return redirect(url_for("axm_requests"))
            return redirect(url_for("requests"))

        else:
            flash(gettext("Order data not sent."))
            return redirect(url_for("requests"))

    formCustomer.datetime.data = datetime.utcnow()
    return render_template('requests/createRequest.html',
                           title=gettext("Accept order from customer"),
                           formCustomer=formCustomer,
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例2: placeorder

# 需要导入模块: from models import Request [as 别名]
# 或者: from models.Request import active_flg [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.active_flg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。