Beispiel #1
0
def editMenuItem(restaurant_id, menu_id):
    """page to edit a menu item."""

    if 'access_token' not in flask_session:
        return logInRedirect()
    restaurant = session.query(Restaurant).filter_by(id = restaurant_id).first()
    user_id = getUserId(flask_session['email'],flask_session['google_plus_id'])
    if not restaurant.user_id == user_id:
        return redirect(url_for("publicMenu",restaurant_id = restaurant_id))
        flash("Only restaurant owners can edit items.")

    if request.method == "POST":
        edited_name = request.form['edited_name']
        print "\neditMenuItem POST triggered, name is: ", edited_name
        old_name = session.query(MenuItem).filter_by(id = menu_id).first().name

        result = session.execute(""" UPDATE menu_item
                                     SET name=:edited_name
                                     WHERE id=:edited_menu_item_id; """,
                                 { "edited_name": edited_name,
                                   "edited_menu_item_id": menu_id}
                                 )
        session.commit()
        flash( "item '" +  old_name + "' edited to '" + edited_name + "'. Jawohl!")
        return redirect(url_for("showMenu", restaurant_id=restaurant_id))

    else:
        menuItem = session.query(MenuItem).filter_by(id = menu_id).first()
        return render_template('editMenuItem.html',
                                  restaurant = restaurant,
                                  menuItem = menuItem )
Beispiel #2
0
def deleteMenuItem(restaurant_id, menu_id):
    """page to delete a menu item."""

    if 'access_token' not in flask_session:
        return logInRedirect()
    restaurant = session.query(Restaurant).filter_by(id = restaurant_id).first()
    user_id = getUserId(flask_session['email'],flask_session['google_plus_id'])
    if not restaurant.user_id == user_id:
        flash("Only restaurant owners can delete items.")
        return redirect(url_for("publicMenu",restaurant_id = restaurant_id))

    if request.method == "POST":
        print "\ndeleteMenuItem POST triggered!, menu_id is: ", menu_id
        deletedMenuItem = session.query(MenuItem).filter_by(id = menu_id).first()
        session.delete(deletedMenuItem)
        session.commit()
        flash( "item '" + deletedMenuItem.name + "' deleted. Auf Wiedersehen!")
        return redirect(url_for("showMenu", restaurant_id=restaurant_id))

    else:
        print "restaurants/delete accessed..."
        menuItem = session.query(MenuItem).filter_by(id = menu_id).first()
        return render_template( 'deleteMenuItem.html',
                                   menuItem = menuItem,
                                   restaurant = restaurant )
Beispiel #3
0
def createUser(flask_session):
    newUser = User(
        name=flask_session["username"],
        picture=flask_session["picture"],
        link=flask_session["link"],
        email=flask_session["email"],
        google_plus_id=flask_session["google_plus_id"],
    )
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(google_plus_id=flask_session["google_plus_id"]).one()
    return user.id
Beispiel #4
0
def newRestaurant():
    """page to create a new menu item."""

    if "access_token" not in flask_session:
        return logInRedirect()
    user_id = getUserId(flask_session["email"], flask_session["google_plus_id"])

    if request.method == "POST":
        new_name = request.form["new_name"]
        print "\nnewRestaurant POST triggered, name is: ", new_name
        newRestaurant = Restaurant(name=new_name, user_id=user_id)
        session.add(newRestaurant)
        session.commit()
        flash("new restaurant '" + new_name + "' created!")
        print "POST worked!"

        return redirect(url_for("showRestaurants"))

    else:
        return render_template("newRestaurant.html")
Beispiel #5
0
def deleteRestaurant(restaurant_id):
    """page to delete a restaurant (authorized only for creators)."""

    if "access_token" not in flask_session:
        return logInRedirect()
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).first()
    user_id = getUserId(flask_session["email"], flask_session["google_plus_id"])
    if not restaurant.user_id == user_id:
        flash("Only restaurant owners can delete restaurants.")
        return redirect(url_for("publicMenu", restaurant_id=restaurant_id))

    if request.method == "POST":
        print "\ndeleteRestaurant POST triggered!"
        deletedRestaurant = session.query(Restaurant).filter_by(id=restaurant_id).first()
        session.delete(deletedRestaurant)
        session.commit()
        flash("item '" + deletedRestaurant.name + "' deleted. Auf Wiedersehen!")
        return redirect(url_for("showRestaurants"))

    else:
        print "restaurants/id/delete accessed..."
        return render_template("deleteRestaurant.html", restaurant=restaurant)
Beispiel #6
0
def newMenuItem(restaurant_id):
    """page to create a new menu item."""

    if 'access_token' not in flask_session:
        return logInRedirect()
    restaurant = session.query(Restaurant).filter_by(id = restaurant_id).first()
    user_id = getUserId(flask_session['email'],flask_session['google_plus_id'])
    if not restaurant.user_id == user_id:
        flash("Only restaurant owners can add new items.")
        return redirect(url_for("publicMenu",restaurant_id = restaurant_id))

    if request.method == "POST":
        new_name = request.form['new_name']
        print "\nnewMenuItem POST triggered, name is: ", new_name
        newMenuItem = MenuItem( name=new_name,
                                restaurant_id=restaurant.id )
        session.add(newMenuItem)
        session.commit()
        flash( "new item '" + new_name + "' created!")
        print "POST worked!"
        return redirect(url_for("showMenu", restaurant_id=restaurant.id))

    else:
        return render_template('newMenuItem.html', restaurant = restaurant)