예제 #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 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])
예제 #4
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])
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)