예제 #1
0
def restaurantMenuItemEdit(restaurant_id, menu_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)
    menuItem = MenuItem.get_by_id(menu_id)

    if not (restaurant and menuItem):
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))

    if login_session.get('user_id') != menuItem.user.key().id():
        flash("Permission denied", "user-error")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))

    if request.method == 'POST':
        if request.form['name']:
            menuItem.name = request.form['name']
        if request.form['description']:
            menuItem.description = request.form['description']
        if request.form['price']:
            menuItem.price = float(request.form['price'])
        if request.form['course']:
            menuItem.course = request.form['course']

        menuItem.put()

        flash('Menu Item Successfully Edited', 'menu')
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('menuItemEdit.html', menuItem=menuItem, restaurant=restaurant, login_session=login_session)
예제 #2
0
def restaurantMenuItemNew(restaurant_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)

    if not restaurant:
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))


    if 'user_id' not in login_session:
        flash("You are not signed in", "user-error")
        return render_template('menuItemNew.html', restaurant=restaurant, login_session=login_session)


    if request.method == 'POST':
        if request.form['name']:
            user = User.get_by_id(login_session['user_id'])
            newItem = MenuItem(name=request.form['name'], description=request.form['description'],
                               price=float(request.form['price']), course=request.form['course'], restaurant=restaurant,
                               parent=use_key(), user=user)
            newItem.put()

            flash('Menu Item Created', 'menu')
            return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('menuItemNew.html', restaurant=restaurant, login_session=login_session)
예제 #3
0
def lotsofmenus():

    q = Restaurant.all()
    if q.count() > 0:
        return "Database already exists"
    else:
        populateDB()
        return "Added menu successfully"
예제 #4
0
def restaurantNew():
    """ """
    if 'user_id' not in login_session:
        flash("You are not signed in", "user-error")
        return render_template('restaurantNew.html', login_session=login_session)

    if request.method == 'POST':
        name = request.form['name']
        user_id = login_session['user_id']
        user = User.get_by_id(user_id)

        if name:
            newRestaurant = Restaurant(name=name, user=user, parent=use_key())
            newRestaurant.put()

            flash("New Restaurant Created", "restaurant")
            return redirect(url_for('mainPage'))
    else:
        return render_template('restaurantNew.html', login_session=login_session)
예제 #5
0
def restaurantMenuItemJson(restaurant_id, menu_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)
    menuItem = MenuItem.get_by_id(menu_id)

    if not (restaurant and menuItem):
        return redirect(url_for('mainPage'))

    return jsonify(MenuItem=[menuItem.serialize])
예제 #6
0
def restaurantMenuJson(restaurant_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)

    if not restaurant:
        return redirect(url_for('mainPage'))

    menuItems = MenuItem.all()
    menuItems.filter("restaurant = ", restaurant.key())

    return jsonify(MenuItems=[menuItem.serialize for menuItem in menuItems])
예제 #7
0
def restaurantMenu(restaurant_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)

    if not restaurant:
        return redirect(url_for('mainPage'))

    menuItems = getMenuItems(restaurant)
    authors = getMenuCreators(restaurant)

    return render_template("restaurantMenu.html", restaurant=restaurant, menuItems=menuItems,
                           login_session=login_session, authors=authors)
예제 #8
0
def mainPage():
    restaurants = list()
    restaurantQuery = Restaurant.all()
    restaurantQuery.order("created")

    for restaurant in restaurantQuery:
        r = dict()
        r['id'] = restaurant.key().id()
        r['name'] = restaurant.name
        r['courses'] = getMenuItems(restaurant)
        r['avgPrice'] = render_price(r['courses'])
        r['user_id'] = restaurant.user.key().id()

        restaurants.append(r)

    return render_template('front.html', restaurants=restaurants, login_session=login_session)
예제 #9
0
def restaurantMenuItemDelete(restaurant_id, menu_id):
    """ List all the menu for specific restaurant """

    restaurant = Restaurant.get_by_id(restaurant_id)
    menuItem = MenuItem.get_by_id(menu_id)

    if not (restaurant and menuItem):
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))

    if login_session.get('user_id') != menuItem.user.key().id():
        flash("Permission denied", "user-error")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))

    if request.method == 'POST':
        menuItem.delete()

        flash('Menu Item Successfully Deleted', 'menu')
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('menuItemDelete.html', menuItem=menuItem, restaurant=restaurant, login_session=login_session)
예제 #10
0
def restaurantEdit(restaurant_id):
    """ """
    restaurant = Restaurant.get_by_id(restaurant_id)

    if not restaurant:
        return redirect(url_for('mainPage'))

    if login_session.get('user_id') != restaurant.user.key().id():
        flash("Permission denied", "user-error")
        return redirect(url_for('mainPage'))

    if request.method == 'POST':
        name = request.form['name']
        if name:
            restaurant.name = name
            restaurant.put()

            flash('Restaurant Successfully Edited', 'restaurant')
            return redirect(url_for('mainPage'))
    else:
        return render_template('restaurantEdit.html', restaurant=restaurant, login_session=login_session)
예제 #11
0
def restaurantDelete(restaurant_id):
    """ """
    restaurant = Restaurant.get_by_id(restaurant_id)

    if not restaurant:
        return redirect(url_for('mainPage'))

    if login_session.get('user_id') != restaurant.user.key().id():
        flash("Permission denied", "user-error")
        return redirect(url_for('mainPage'))

    menuItems = MenuItem.all()
    menuItems.filter("restaurant = ", restaurant.key())

    if request.method == 'POST':
        for menuItem in menuItems:
            menuItem.delete()

        restaurant.delete()

        flash('Restaurant Successfully Deleted', 'restaurant')
        return redirect(url_for('mainPage'))
    else:
        return render_template('restaurantDelete.html', restaurant=restaurant, login_session=login_session)
예제 #12
0
def restaurantJson():
    """ """
    restaurants = Restaurant.all()
    return jsonify(Restaurants=[restaurant.serialize for restaurant in restaurants])