Пример #1
0
def list_menu_items(restaurant_id):
    creator = database_operations.get_user(database_operations.get_restaurant(restaurant_id).user_id)
    if 'user_id' not in login_session:
        print 'public'
        return render_template('public_menu.html',
                               items = database_operations.get_menu_items_for_restaurant(restaurant_id),
                               restaurant = database_operations.get_restaurant(restaurant_id),
                               creator= creator)
    if creator.id == login_session['user_id']:
        if not database_operations.get_menu_items_for_restaurant(restaurant_id):
            flash("{} has no menu yet, please add an item!".format(database_operations.get_restaurant(restaurant_id).name))
            return redirect(url_for('add_new_menu_item', restaurant_id=restaurant_id))
        print 'private'
        return render_template('menu.html',
                               restaurant=database_operations.get_restaurant(restaurant_id),
                               items=database_operations.get_menu_items_for_restaurant(restaurant_id))
    else:
        if not database_operations.get_menu_items_for_restaurant(restaurant_id):
            flash("{} has no menu yet!".format(database_operations.get_restaurant(restaurant_id).name))
            return redirect(url_for('list_restaurants'))
        print 'public'
        return render_template('public_menu.html',
                               items = database_operations.get_menu_items_for_restaurant(restaurant_id),
                               restaurant = database_operations.get_restaurant(restaurant_id),
                               creator= creator)
Пример #2
0
def restaurant_menu_json(restaurant_id):
    menu_items = database_operations.get_menu_items_for_restaurant(restaurant_id)
    return jsonify(items=[item.serialize for item in menu_items])