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


Python Order.select方法代码示例

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


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

示例1: orders_index

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import select [as 别名]
def orders_index():
    type = request.args.get('type', None)
    page = int(request.args.get('page', 0))
    count = abs(int(request.args.get('count', 0)))
    offset = count * (page - 1)
    if offset < 0:
        offset = 0

    orders = Order.select().order_by(Order.id.desc())
    if (type == 'paid'):
        orders = orders.where(Order.status == Order.PAID, Order.canceled == False)
    elif (type == 'confirmed'):
        orders = orders.where(Order.status == Order.CONFIRMED, Order.canceled == False)
    elif (type == 'delivering'):
        orders = orders.where(Order.status == Order.IN_DELIVERY, Order.canceled == False)
    elif (type == 'delivered'):
        orders = orders.where(Order.status == Order.DELIVERED, Order.canceled == False)
    elif (type == 'canceled'):
        orders = orders.where(Order.canceled == True)

    total_count = orders.count()

    if (type != 'confirmed'):
        orders = orders.limit(count).offset(offset)

    result = []
    for o in orders:
        result.append(o.details())

    return render.ok({'orders': result, 'total': total_count, 'classfied': classified_count()})
开发者ID:shanggaohui,项目名称:20151124,代码行数:32,代码来源:order.py

示例2: classified_count

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import select [as 别名]
def classified_count():
    orders = Order.select()
    total_count = orders.count()
    paid_count = orders.where(Order.status == Order.PAID, Order.canceled == False).count()
    confirmed_count = orders.where(Order.status == Order.CONFIRMED, Order.canceled == False).count()
    delivering_count = orders.where(Order.status == Order.IN_DELIVERY, Order.canceled == False).count()
    delivered_count = orders.where(Order.status == Order.DELIVERED, Order.canceled == False).count()
    canceled_count = orders.where(Order.canceled == True).count()

    return {'total': total_count,
            'paid': paid_count,
            'confirmed': confirmed_count,
            'delivering': delivering_count,
            'delivered': delivered_count,
            'canceled': canceled_count
            }
开发者ID:shanggaohui,项目名称:20151124,代码行数:18,代码来源:order.py

示例3: orders_of_days

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import select [as 别名]
def orders_of_days():
    #    data = json.loads(request.data or '{}')
    #    if data is None:
    #        return render.error("Nothing input")
    #    if 'days' not in data:
    #        return render.error("Invalid format")

#    duration = abs(int(data.get('days', 0)))

    duration = abs(int(request.args.get('days', 0)))

#    orders = Order.select().where(Order.status >= Order.PAID, Order.canceled == False, (datetime.datetime.now()  - Order.create_time).days == duration)

    today = datetime.date.today()
    now = datetime.datetime.now()
    today_zero_time = datetime.datetime(now.year,now.month,now.day,0,0,0)
    #datetime.datetime.strftime(today, '%Y-%m-%d %H:%M:%S')

    orders = Order.select().where(Order.status >= Order.PAID, Order.canceled == False, Order.create_time>= (today_zero_time-datetime.timedelta(days = duration)) )

    re = []
    for n in range(0,duration):
        if duration == 0:
            duration_orders = orders
        else:
            duration_orders = orders.where( Order.create_time>= (today_zero_time-datetime.timedelta(days = n)), Order.create_time < (today_zero_time-datetime.timedelta(days = n-1)) )
        if duration_orders is None:
            continue

        count = duration_orders.count()

        total_price = 0
        for o in duration_orders:
            total_price += o.cash_amount

#total_price = sum(duration_orders.items.cash_amount)
        result = {}
        result['date'] = today-datetime.timedelta(days = n)
        result['count'] = count
        result['total_price'] = total_price
        re.append(result)

    return render.ok(re)
开发者ID:shanggaohui,项目名称:20151124,代码行数:45,代码来源:order.py

示例4: order

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import select [as 别名]
def order(stock_id=None, quantity=""):
    quantity = int(quantity)

    if quantity != "" and quantity > 0:  # validate the quantity given
        stock = Stock.get(Stock.id == stock_id)

        orders = (
            Order.select(fn.sum(Order.quantity)).where(Order.stock == stock.id).scalar()
        )  # Get the current number of orders

        if orders == None:  # I don't want a TypeError below
            orders = 0

        if quantity <= (
            stock.minimum_quantity - orders
        ):  # verify if quantity is less than or equal to the needed orders
            price = quantity * stock.price  # calculate the amount the buyer has to pay
            Order.make_order(buyer=1, stock=stock, quantity=quantity, price=price)

            if (
                stock.minimum_quantity == Order.select(fn.sum(Order.quantity)).where(Order.stock == stock.id).scalar()
            ):  # check if the target has been met
                stock.bought = True  # update stock and set it to saved
                stock.save()
                orders = Stock.get(Stock.id == stock_id).orders

                for order in orders:
                    order.ready = True
                    order.save()

                    # replace the old stock with a fresh one with no orders yet
                new_stock = Stock.enter_stock(
                    product=stock.product,
                    first_description=stock.first_description,
                    second_description=stock.second_description,
                    third_description=stock.third_description,
                    unit=stock.unit,
                    quantity=stock.quantity,
                    minimum_quantity=stock.minimum_quantity,
                    brand=stock.brand,
                    supplier=stock.supplier,
                    price=stock.price,
                )

                # send SMS's to shippers notifying them of ready deliveries
                for order in stock.orders:
                    shippers = Courier.select()

                    for shipper in shippers:
                        # Account Sid and Auth Token from twilio.com/user/account
                        account_sid = "AC7c8362f62f825e5184fe40e25958623d"
                        auth_token = "834c6ea95160009d251b3f06893768b2"
                        client = TwilioRestClient(account_sid, auth_token)

                        message = client.messages.create(
                            body="Shipping: {} to {}. Reply with your price".format(
                                order.stock.supplier.address, order.buyer.address
                            ),
                            to="+{}".format(str(shipper.phone)),
                            from_="+14782885892",
                        )
                        print(message.sid)

    return redirect(url_for("index"))
开发者ID:RoundRound,项目名称:round,代码行数:66,代码来源:site.py


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