コード例 #1
0
def delete_menu_item(restaurant_id, menu_id):
    username = login_session.get('username')
    if username is None:
        return redirect('/login')
    form = DeleteForm(request.form)
    restaurant = Restaurant.query.filter_by(id=restaurant_id).one()
    # Check if the current user is the creator
    if login_session.get('user_id') != restaurant.user_id:
        return "<script>function myFunction() {" \
               "alert('You are not authorized to delete menu items in " \
               "this restaurant. Please create your own restaurant in " \
               "order to delete menu items.');" \
               "}</script><body onload='myFunction()'>"
    item_to_delete = MenuItem.query.filter_by(id=menu_id).one()
    if form.validate_on_submit():
        db.session.delete(item_to_delete)
        db.session.commit()
        if app.debug:
            app.logger.debug("Menu item {} successfully deleted".format(
                (item_to_delete.id, item_to_delete.name))
            )
        flash("Menu item {} successfully deleted".format(
            (item_to_delete.id, item_to_delete.name))
        )
        return redirect(url_for('restaurant_menu',
                                restaurant_id=restaurant_id))
    else:
        return render_template('deleteMenuItem.html', form=form,
                               item=item_to_delete,
                               restaurant_id=restaurant_id)
コード例 #2
0
def delete_restaurant(restaurant_id):
    username = login_session.get('username')
    if username is None:
        return redirect('/login')
    form = DeleteForm(request.form)
    restaurant = Restaurant.query.filter_by(id=restaurant_id).one()
    # Check if the current user is the creator
    if login_session.get('user_id') != restaurant.user_id:
        return "<script>function myFunction() {" \
               "alert('You are not authorized to delete this restaurant. " \
               "Please create your own restaurant in order to delete.');" \
               "}</script><body onload='myFunction()'>"
    if form.validate_on_submit():
        db.session.delete(restaurant)
        db.session.commit()
        if app.debug:
            app.logger.debug("Restaurant {} deleted!".format(
                (restaurant.id, restaurant.name)))
        flash("Restaurant {} deleted!".format(
            (restaurant.id, restaurant.name)))
        return redirect(url_for('show_restaurants'))
    else:
        return render_template('deleterestaurant.html',
                               form=form,
                               restaurant=restaurant)
コード例 #3
0
def delete_menu_item(restaurant_id, menu_id):
    username = login_session.get('username')
    if username is None:
        return redirect('/login')
    form = DeleteForm(request.form)
    restaurant = Restaurant.query.filter_by(id=restaurant_id).one()
    # Check if the current user is the creator
    if login_session.get('user_id') != restaurant.user_id:
        return "<script>function myFunction() {" \
               "alert('You are not authorized to delete menu items in " \
               "this restaurant. Please create your own restaurant in " \
               "order to delete menu items.');" \
               "}</script><body onload='myFunction()'>"
    item_to_delete = MenuItem.query.filter_by(id=menu_id).one()
    if form.validate_on_submit():
        db.session.delete(item_to_delete)
        db.session.commit()
        if app.debug:
            app.logger.debug("Menu item {} successfully deleted".format(
                (item_to_delete.id, item_to_delete.name)))
        flash("Menu item {} successfully deleted".format(
            (item_to_delete.id, item_to_delete.name)))
        return redirect(url_for('restaurant_menu',
                                restaurant_id=restaurant_id))
    else:
        return render_template('deleteMenuItem.html',
                               form=form,
                               item=item_to_delete,
                               restaurant_id=restaurant_id)
コード例 #4
0
def delete_restaurant(restaurant_id):
    username = login_session.get('username')
    if username is None:
        return redirect('/login')
    form = DeleteForm(request.form)
    restaurant = Restaurant.query.filter_by(id=restaurant_id).one()
    # Check if the current user is the creator
    if login_session.get('user_id') != restaurant.user_id:
        return "<script>function myFunction() {" \
               "alert('You are not authorized to delete this restaurant. " \
               "Please create your own restaurant in order to delete.');" \
               "}</script><body onload='myFunction()'>"
    if form.validate_on_submit():
        db.session.delete(restaurant)
        db.session.commit()
        if app.debug:
            app.logger.debug("Restaurant {} deleted!".format(
                (restaurant.id, restaurant.name)))
        flash("Restaurant {} deleted!".format(
            (restaurant.id, restaurant.name)))
        return redirect(url_for('show_restaurants'))
    else:
        return render_template('deleterestaurant.html', form=form,
                               restaurant=restaurant)