Esempio n. 1
0
def item(request, item_id):
    '''Renders a single item on a page that allows the customer to
    order one or more units of it.'''
    logger.debug({'item_id':item_id})
    item = dao.get_item(item_id)
    item['id'] = item['_id']
    logger.info('rendering item: %s', item)
    return render(request, 'index.html',
                 {'template':'item.html', 'title':item['name'], 'item':item})
Esempio n. 2
0
def place_order(request, item_id, client_id):
    '''Places an order for qty units of item_id from client_id. This
    should add the order to the DB, show the user a confirmation
    message and redirect them to the previous section they were
    browsing'''
    # TODO: orders should have an array of events. Validate all input.
    quantity = request.POST['quantity']
    seat_id = request.session['seat_id']
    logger.info('item_id:%s, client_id:%s, quantity:%s', item_id, client_id, quantity)
    dao.add_order(item_id, quantity, client_id, seat_id)
    item_name = dao.get_item(item_id)['name']
    message = '{} {} coming!. Seat back and relax.'.format(quantity, item_name)
    return render(request, 'index.html',
                  {'template':'confirmation.html', 'message':message})
Esempio n. 3
0
def bill_place_order(request, bill_id, item_id):
    client_id = request.session['client_id']
    bill = dao.get_bill(bill_id)
    item = dao.get_item(item_id)
    if request.POST:
        quantity = request.POST['quantity']
        comment = request.POST['comment']
        menu = dao.get_menu_of_seat(client_id, bill['seat'])
        if item['available']:
            path = dao.get_item_path(item['id'], menu)
            dao.add_order(item['id'], quantity, comment, client_id, bill['seat'], menu, path, bill['bill_number'])
            message = '{} order of {} placed'.format(quantity, item['name'])
        else:
            message = '{} is not available at the moment.'.format(item['name'])
        return render(request, 'index_screen.html',
                  {'template':'confirmation_bill.html', 'message':message})
    
    return render(request, 'index_screen.html',
                  {'template': 'bill_place_order.html',
                   'bill_number': bill['bill_number']})
Esempio n. 4
0
def place_order(request, item_id, client_id):
    '''Places an order for qty units of item_id from client_id. This
    should add the order to the DB, show the user a confirmation
    message and redirect them to the previous section they were
    browsing'''
    # TODO: orders should have an array of events. Validate all input.
    quantity = request.POST['quantity']
    comment = request.POST['comment']
    seat_id = request.session['seat_id']
    bill_n = request.session['bill_n']
    menu_id = request.session['menu_id']
    path = request.session['path']
    logger.info('item_id:%s, client_id:%s, quantity:%s', item_id, client_id, quantity)
    item_name = dao.get_item(item_id)['name']
    if dao.is_available(item_id):
        dao.add_order(item_id, quantity, comment, client_id, seat_id, menu_id, path, bill_n)
        message = '{} {} ya vienen! Sientate y relajate.'.format(quantity, item_name)
    else:
        message = '{} no esta disponible en estos momentos.'.format(item_name)
    return render(request, 'index.html',
                  {'template':'confirmation.html', 'message':message})
Esempio n. 5
0
def explo(data, name='', level = 0, path=[], tree = {'data': []}):
    if 'structure' in data:
        for child in data['structure']:
            explo(data['structure'][child], name=child, tree = tree)
    elif type(data) is dict:
        level += 1
        ##### SECTIONS #####
        path.insert(level-1, name)
        path = path[:level]
        eval(p2d(path, level)).insert(0, {'data': name, 'attr': {'rel': 'section'},'state': 'open','children':[]})
        for child in data:
            explo(data[child], name=child, level=level, path=path, tree=tree)
    elif type(data) is list:
        level += 1
        ##### SUBSECTIONS ######
        path.insert(level-1, name)
        path = path[:level]
        eval(p2d(path, level)).insert(0, {'data': name, 'attr': {'rel': 'subsection'}, 'state': 'open','children':[]})
       
        level += 1
        for child in data:
            ##### ITEMS #####
            eval(p2d(path, level)).insert(0, {'data': dao.get_item(child)['name'], 'attr': {'id': child, 'rel': 'item'}})
Esempio n. 6
0
def explore_mongo(data, name='', level = 0, path=[], tree = {'data': []}):
    '''Explores the menu in mongo with recursion'''
    if 'structure' in data:
        for child in data['structure']:
            explore_mongo(data['structure'][child], name=child, tree = tree)
    elif type(data) is dict:
        level += 1
        ##### SECTIONS #####
        path.insert(level-1, name)
        path = path[:level]
        eval(path_2_list(path, level)).insert(0, {'data': name, 'attr': {'rel': 'section'},'state': 'open','children':[]})
        for child in data:
            explore_mongo(data[child], name=child, level=level, path=path, tree=tree)
    elif type(data) is list:
        level += 1
        ##### SUBSECTIONS ######
        path.insert(level-1, name)
        path = path[:level]
        eval(path_2_list(path, level)).insert(0, {'data': name, 'attr': {'rel': 'subsection'}, 'state': 'open','children':[]})
        level += 1
        for child in reversed(data):
            ##### ITEMS #####
            item = dao.get_item(child)
            eval(path_2_list(path, level)).insert(0, {'data': item['name'], 'attr': {'id': child, 'rel': 'item', 'name': item['name'], 'price': item['price'], 'description': item['description']}})