Exemplo n.º 1
0
def cancel_order(request, order_id):
    '''Cancels the specified order if the order corresponds to the
    seat of the user sending this request. TODO: should this use
    update_order instead? if so, the html would need to contain a form
    per item in the list, which might not be a good idea.'''
    logger.debug({'order':order_id})
    client_id = request.session['client_id']
    update = {}
    try: 
        order = dao.get_order(order_id)
        sid = request.session['seat_id']
        if order['seat_id'] != sid:
            return HttpResponseForbidden('Only the user who placed the order can cancel it!')
        if order['status'] == dao.ORDER_PLACED:
            update['status'] = dao.ORDER_CANCELED
            res = dao.update_order(order_id, update)
        else:
            return HttpResponseForbidden('Ordered can not be canceled. The ordered is already processed')
        if res != dao.ORDER_CANCELED:
            logger.error('error canceling order %s from seat %s', order_id, sid)
            return http.HttpResponseServerError('failed to update order status, please try again later')
    except KeyError as e:
        logger.error('sessions does not contain a seat ID - not canceling order %s'. order_id)
        return HttpResponseForbidden
    orders = customer_orders(request)
    sub_total = dao.orders_sub_total(orders)
    return render_orders(request, client_id, orders, customer_mods, sub_total=sub_total)
Exemplo n.º 2
0
def update_order(request, order_id):
    '''Updates the specified order with the params in the request'''
    logger.info('order:%s', order_id)
    update = {'status': request.POST['status'],
              'comment': request.POST['comment']}
    res = dao.update_order(order_id, update)
    client_id = dao.get_client_id(order_id)
    return render(request, 'index.html',
                  {'template':'updated.html', 'client_id':client_id})
Exemplo n.º 3
0
def update_order(request, order_id):
    '''Updates the specified order with the params in the request'''
    logger.info('order:%s', order_id)
    status = request.POST['status']
    res = dao.update_order(order_id, status)
    if res != status:
        # TODO: return a 503?
        return
    client_id = dao.get_client_id(order_id)
    return render(request, 'index.html',
                  {'template':'updated.html', 'client_id':client_id})