Beispiel #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)
Beispiel #2
0
def list_orders(request, query={}):
    '''Lists orders in the specified client's queue. It defaults to
    the pending orders.'''
    client_id = request.session['client_id']
    
    if request.POST:
        query = {}
        statii = []
        for status in dao.ORDER_STATII:
            if status in request.POST:
                statii.append(status)
                query['status'] = statii
        bill_statii = []
        for status in dao.BILL_STATII:
            if status in request.POST:
                bill_statii.append(status)
                query['bill_status'] = bill_statii    
        if 'seats' in request.POST:
            query['seat_id'] = [str(i) for i in request.POST.getlist('seats')]
        if 'paths' in request.POST:
            query['path'] = [str(i) for i in request.POST.getlist('paths')]
        if 'menus' in request.POST:
            query['menu_id'] = [str(i) for i in request.POST.getlist('menus')]
        if request.POST['bill_number'] != '':
            query['bill_number'] = int(request.POST['bill_number'])
        request.session['query'] = query

    if not any(query):
        query = request.session['query']      
    orders = dao.list_orders(client_id, query)
    logger.info({'orders': orders,'modifiers':server_mods})
    return render_orders(request, client_id, orders, server_mods, is_screen=True)
Beispiel #3
0
def screen_refresh(request):
    client_id = request.session['client_id'] 
    query = request.session['query']
    orders = dao.list_orders(client_id, query=query)
    for item in orders:
        item['status'] = item['status'].replace('_','').capitalize()

    return render_orders(request, client_id, orders, server_mods, is_screen=True)
Beispiel #4
0
def myorders(request):
    ''' Lists orders placed from this session as indicated by the
    session's seat_id and client_it. It will display orders that are
    in placed, prepared or served status.'''
    orders = customer_orders(request)
    sub_total = dao.orders_sub_total(orders)
    client_id = request.session['client_id']
    return render_orders(request, client_id, orders, customer_mods, sub_total=sub_total)
Beispiel #5
0
def list_orders(request, client_id, query={}):
    '''Lists orders in the specified client's queue. It defaults to
    the pending orders. TODO: provide a way for the server or manager
    to filter by any combination of date, status and seat'''
    logger.debug({'client_id':client_id, 'query':query})
    # default to ORDER_PLACED for now
    if 'status' not in query:
        query['status'] = dao.ORDER_PLACED
    orders = dao.list_orders(client_id, query)
    logger.info({'orders': orders,'modifiers':server_mods})
    return render_orders(request, orders, server_mods)
Beispiel #6
0
def myorders(request):
    ''' Lists orders placed from this session as indicated by the
    session's seat_id and client_it. It will display orders that are
    in placed, prepared or served status.'''
    orders = customer_orders(request)
    return render_orders(request, orders, customer_mods)