コード例 #1
0
def todo():
    order_data = list(order.get_todo_order())
    return render_template(
        "todo.html",
        order_data=order_data,
        auth=current_user.role,
        name=current_user.name,
        id=current_user.id,
    )
コード例 #2
0
def update_order_state():
    data = request.get_json()
    result = order.update_state(data)
    try:
        cancel_content = data["content"]
    except KeyError:
        cancel_content = ""
    message = {
        "doing": {
            "title": "訂單已接受",
            "content": "老闆已接受您的訂單"
        },
        "cancel": {
            "title": "訂單被拒絕",
            "content": "抱歉,老闆拒絕了您的訂單, 拒絕原因為:" + cancel_content,
        },
        "finish": {
            "title": "訂單已完成",
            "content": "餐點已製作完成,請儘速來取餐"
        },
    }
    if result:
        try:
            token = user.get_token_by_username(result["userName"])["token"]
            # push to customer
            if data["state"] in message:
                message[data["state"]].update({
                    "url":
                    url_for("order_web.state", _external=True),
                    "detail":
                    json.dumps(result),
                })
                push.send_to_customer([token], message[data["state"]])
        except (ValueError, messaging.UnregisteredError):
            pass
        finally:
            # push to admin
            if data["state"] == "doing":
                push.send_to_topic(
                    {
                        "type":
                        "admin-order-update",
                        "detail":
                        json.dumps(
                            list(order.get_todo_order(id=result["_id"]))[0]),
                    },
                    push.TOPIC_ADMIN,
                )
            return "", 200
    else:
        return "", 404
コード例 #3
0
def todo():
    return jsonify(list(order.get_todo_order()))