示例#1
0
def create_order_from(payload):
    # validate payload
    validate(payload, Orders().schema)

    payload["status"] = Orders().created
    payload["tasks"] = {}
    payload["statuses"] = [{
        "status": Orders().created,
        "on": datetime.datetime.now(),
        "payload": None
    }]

    # actually create Order
    order_id = Orders().insert_one(payload).inserted_id

    # define and record fname for this order
    if "fname" not in payload:
        fname = f"{order_id}.img"
    else:
        short_id = str(order_id)[:10]
        if "{rand}" in payload["fname"]:
            fname = payload["fname"].replace("{rand}", short_id)
        else:
            stem, ext = os.path.splitext(payload["fname"])
            fname = "".join((stem + f"_{short_id}", ext))
    Orders.update(order_id, {"fname": fname})

    # send email about new order
    send_order_created_email(order_id)

    # create creation task
    Orders.create_creator_task(order_id)

    return order_id
示例#2
0
def get_full_context(order_id, extra={}):
    order = Orders().get_with_tasks(order_id, {"logs": 0})
    order.update({
        "id": order_id,
        "status": order["statuses"][-1],
        "min_id": order_id[:8] + order_id[-3:],
    })
    context = {"order": order}
    context.update(extra)
    return context