Exemple #1
0
def admin_orders_action(req, id):
    check_login(req)
    check_token(req, req.form.get('token'))
    check_right(req, module_right)

    if req.uri.endswith('/storno'):
        ostate = STATE_STORNED
    elif req.uri.endswith('/process'):
        ostate = STATE_PROCESS
    elif req.uri.endswith('/sent'):
        ostate = STATE_SENT
    elif req.uri.endswith('/close'):
        ostate = STATE_CLOSED
    elif req.uri.endswith('/wait_for_paid'):
        ostate = STATE_WAIT_FOR_PAID
    elif req.uri.endswith('/wait_for_pick_up'):
        ostate = STATE_WAIT_FOR_PICK_UP
    else:
        raise SERVER_RETURN(state.HTTP_BAD_REQUEST)

    note = req.form.getfirst('note', '', uni)

    order = Order(id)
    if order.set_state(req, ostate, note) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    if ostate != STATE_CLOSED:
        send_order_status(req, order)

    redirect(req, '/admin/eshop/orders/%d' % id)
Exemple #2
0
def admin_orders_mod(req, id):
    check_login(req)
    check_right(req, module_right)

    order = Order(id)
    if order.get(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency

    order.calculate()
    return generate_page(req, "admin/eshop/orders_mod.html",
                         token=create_token(req),
                         order=order, cfg=cfg)
Exemple #3
0
def user_orders_storno(req, id):
    check_login(req)
    # TODO: check_token
    check_referer(req, '/eshop/orders/%d' % id)

    message = req.form.getfirst('message', '', uni)

    order = Order(id)
    if order.get(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    if order.client_id != req.login.id:
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    if order.set_state(req, STATE_STORNED, usernote=message) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    send_order_status(req, order)
    redirect(req, '/eshop/orders/%d' % id)
Exemple #4
0
def user_orders_detail(req, id):
    sha = req.args.getfirst('sha', '', str)
    if not sha and not req.login:
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    order = Order(id)
    if order.get(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)
    order.sha = sha1(str(order.create_date)).hexdigest()

    if (sha and sha != order.sha):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)
    # if sha is set, you can see to order
    if (not sha and req.login and order.client_id != req.login.id):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    cfg = Object()
    cfg.addresses_country = req.cfg.addresses_country
    cfg.addresses_region = req.cfg.addresses_region
    cfg.eshop_currency = req.cfg.eshop_currency

    order.calculate()
    return generate_page(req, "eshop/orders_detail.html",
                         order=order, sha=sha, cfg=cfg)
Exemple #5
0
def user_orders(req):
    if not req.login:
        return generate_page(req, "/eshop/orders_for_logined.html")

    check_login(req)
    state = req.args.getfirst('state', -1, int)

    kwargs = {'client_id': req.login.id}
    if state >= 0:
        kwargs['state'] = state

    pager = Pager(sort='desc')
    items = Order.list(req, pager, **kwargs)

    return generate_page(req, "/eshop/orders.html", pager=pager, items=items,
                         state=state)
Exemple #6
0
def admin_orders(req):
    check_login(req)
    check_right(req, module_right)

    state = req.args.getfirst('state', -1, int)
    client = req.args.getfirst('client', '', uni)

    kwargs = {}
    if state >= 0:
        kwargs['state'] = state
    if client:
        kwargs['client'] = client

    pager = Pager(sort='desc')
    items = Order.list(req, pager, **kwargs)

    return generate_page(req, "admin/eshop/orders.html", pager=pager,
                         items=items, state=state, client=client)
Exemple #7
0
def eshop_cart_pay_and_order(req):
    do_check_mgc(req)
    check_token(req, req.form.get('token'), uri='/eshop/cart/recapitulation')
    cart = ShoppingCart(req)
    # TODO: payment page if could be (paypal, card, transfer)
    order = Order.from_cart(cart)
    if not order:
        redirect(req, '/eshop')
    order.client_id = req.login.id if req.login else None
    retval = order.add(req)
    if retval == order:
        cart.clean(req)
        send_order_status(req, order)
        return generate_page(req, "eshop/shopping_accept.html",
                             order=order)
    if retval[0] == EMPTY_ITEMS:
        redirect(req, '/eshop')
    if retval[0] == NOT_ENOUGH_ITEMS:
        cart.set_not_enought(retval[1])
        cart.store(req)
        redirect(req, '/eshop/cart')