Ejemplo n.º 1
0
def deleteMenuItem(restaurant_id, menu_id):
    if 'username' not in login_session:
        return redirect(url_for('login.user_login'))

    menuItem = query_db.get_one(session, MenuItem, menu_id)
    restaurant = query_db.get_one(session, Restaurant, restaurant_id)

    if request.method == 'GET':
        return render_template('menu/confirmMenuItemDelete.html',
                               restaurant=restaurant,
                               item=menuItem)
    if request.method == 'POST':
        restaurant_path = '/'.join(request.path.split('/')[:3])
        if request.form['should_delete'].lower() == 'yes':
            try:
                query_db.delete(session, menuItem)
                session.commit()

                flash("successfully deleted %s" % menuItem.name)

                return redirect(
                    url_for('restaurant_menu.restaurantMenu',
                            restaurant_id=restaurant.id))
            except:
                session.rollback()
                raise
                return render_template('menu/deleteMenuItemFailed',
                                       restaurant=restaurant,
                                       item=menuItem)
        else:
            return redirect(
                url_for('restaurant_menu.restaurantMenu',
                        restaurant_id=restaurant.id))
Ejemplo n.º 2
0
def deleteRestaurant(restaurant_id):
    if 'username' not in login_session:
        return redirect(url_for('login.user_login'))

    try:
        restaurant = query_db.get_one(session, Restaurant, restaurant_id)
    except:
        raise

    if request.method == 'GET':
        return render_template('restaurants/confirmRestaurantDelete.html',
                restaurant=restaurant)
    if request.method == 'POST':
        params = request.form

        if 'should_delete' in params:
            if params['should_delete']:
                try:
                    query_db.delete(session, restaurant)
                    session.commit()

                    flash("Successfuly deleted %s" % restaurant.name)

                    return redirect(url_for('restaurants.allRestaurants'))
                except:
                    session.rollback()
                    raise
Ejemplo n.º 3
0
def restaurantMenuJSON(restaurant_id):
    try:
        restaurant = query_db.get_one(session, Restaurant, restaurant_id)
        items = query_db.get_items(session, MenuItem, restaurant_id)
        return jsonify(MenuItems=[item.serialize for item in items])
    except:
        raise
Ejemplo n.º 4
0
def editRestaurant(restaurant_id):
    if 'username' not in login_session:
        return redirect(url_for('api.login'))

    restaurant = query_db.get_one(session, Restaurant, restaurant_id)

    if request.method == 'GET':
        return render_template('restaurants/editRestaurant.html', restaurant=restaurant)
    if request.method == 'POST':
        params = request.form
        if 'name' in params.keys():
            restaurant.name = params['name']
        try:
            query_db.update(session, restaurant)
            session.commit()

            flash("Successfully updated %s!" % restaurant.name)

            return redirect(url_for('restaurants.allRestaurants'))
        except:
            session.rollback()
            redirect(url_for('restaurants.allRestaurants'))
            raise
Ejemplo n.º 5
0
def restaurantsJSON():
    restaurants = query_db.get_all(session, Restaurant)

    if request.method == 'GET':
        try:
            return json.dumps(
                [restaurant.serialize for restaurant in restaurants],
                ensure_ascii=False)
        except:
            raise
    elif request.method == 'POST':
        restaurant = Restaurant(name=request.args.get('name'))

        if 'user_id' in request.form:
            restaurant.user_id = request.args.get('user_id')
        else:
            restaurant.user_id = 1
        try:
            query_db.update(session, restaurant)
            session.commit()
            return json.dumps(
                [restaurant.serialize for restaurant in restaurants],
                ensure_ascii=False)
        except:
            session.rollback()
            raise
    elif request.method == 'DELETE':
        try:
            restaurant = query_db.get_one(session, Restaurant,
                                          request.args.get('id'))
            query_db.delete(session, restaurant)
            session.commit()

            return make_response('succes', 200)
        except:
            session.rollback()
            return make_response('error', 404)
Ejemplo n.º 6
0
def restaurantMenuItemJSON(restaurant_id, menu_id):
    try:
        item = query_db.get_one(session, MenuItem, restaurant_id)
        return jsonify(item.serialize)
    except:
        raise
Ejemplo n.º 7
0
def restaurantJSON(restaurant_id):
    try:
        restaurant = query_db.get_one(session, Restaurant, restaurant_id)
        return jsonify(restaurant.serialize)
    except:
        raise