예제 #1
0
def newMenuItem(restaurant_id):
    # verify that a user is logged in
    if 'username' not in login_session:
        return redirect('/login')
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if request.method == 'POST':
        newItem = MenuItem(restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        if request.form['name']:
            newItem.name = request.form['name']
        if request.form['price']:
            newItem.price = request.form['price']
        if request.form['course']:
            newItem.course = request.form['course']
        if request.form['description']:
            newItem.description = request.form['description']
        session.add(newItem)
        session.commit()
        flash("{} menu item Created!".format(newItem.name))
        return redirect(
            url_for('restaurantMenu',
                    restaurant_id=restaurant_id,
                    restaurant=restaurant))
    else:
        return render_template('newmenuitem.html',
                               restaurant_id=restaurant_id,
                               restaurant=restaurant)
예제 #2
0
def newMenuItem(restaurant_id):
    #return 'This page is for making a new menu item for restaurant %s' % restaurant_id
    if request.method == 'POST':
        if request.form.get('name'):
            menu = MenuItem(name=request.form['name'])
            menu.restaurant_id = restaurant_id
            session.add(menu)
        else:
            flash('Menu must have a name!')
            return redirect(url_for('showMenu',restaurant_id= restaurant_id))
        print '2'
        if request.form.get('description'):
            menu.description = request.form['description']
            session.add(menu)
        if request.form.get('course'):
            menu.course = request.form['course']
            session.add(menu)
        if request.form.get('price'):
            menu.price = request.form['price']
            session.add(menu)
        session.commit()
        flash('Menu has been added!')
        return redirect(url_for('showMenu', restaurant_id = restaurant_id))
    else:
        return render_template('newMenuItem.html',restaurant_id = restaurant_id)
예제 #3
0
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['newMenuItemName'])
        newItem.price = request.form['newMenuItemPrice']
        newItem.description = request.form['newMenuItemDescription']
        newItem.restaurant_id = restaurant_id

        session.add(newItem)
        session.commit()
        flash("New menu Item Created Bon Appetit!")

        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        restaurant = session.query(Restaurant).filter_by(
            id=restaurant_id).one()
        # output = ''
        # output += '<html><body>'
        # output += '<h2>Create New Menu Item For Restaurant: %s</h2>' % restaurant.name
        # output += """
        #     <form method = 'POST' enctype='multipart/form-data' action='/restaurants/%s/new'>
        #     <input name='newMenuItemName' type='text' placeholder = "Menu Item Name"></br>
        #     <input name='newMenuItemPrice' type='text' placeholder = "Menu Item Price"></br>
        #     <input name='newMenuItemDescription' type='text' placeholder = "Menu Item Description"></br>
        #     <input type='submit' value='Create'>
        #     </form>
        # """ % restaurant.id
        # output += '</body></html>'
        return render_template('newMenuItem.html', restaurant=restaurant)
예제 #4
0
def addNewMenuItem(session, restaurant_id, name, price, description):
    i = MenuItem(name = name, restaurant_id = restaurant_id)
    i.price = price
    i.description = description
    session.add(i)
    session.commit()
    return i
예제 #5
0
def newMenuItem(restaurant_id):
    """
    :param restaurant_id:
    :return: Allows the user to create a new menu item for the restaurant with the ID specified
    """
    if 'username' not in login_session:
        return redirect('/login')

    # Get the restaurant, items and creator
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    items = session.query(MenuItem).filter_by(restaurant_id = restaurant.id)
    creator = getUserInfo(restaurant.user_id)

    # checks to see if the user is logged in or not
    if 'username' not in login_session or creator.id != login_session['user_id']:
        flash('Only the creator of the restaurant can create a new menu item.')
        return render_template('final_showrestaurant.html', restaurant=restaurant, items=items, CREATOR=creator)

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'])
        newItem.price = request.form['price']
        newItem.description = request.form['description']
        newItem.course = request.form['course']
        newItem.restaurant_id = restaurant_id
        # newItem.user = login_session['user_id']
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created", "success")
        return redirect( url_for('showRestaurant', restaurant_id = restaurant_id) )
    else:
        return render_template('final_newmenuitem.html', restaurant_id=restaurant_id)
예제 #6
0
def fill_menu_item(req_form, restaurant_id):
    item = MenuItem(name=req_form['name'], restaurant_id=restaurant_id)
    if request.form['description']:
        item.description = request.form['description']
    if request.form['price']:
        item.price = request.form['price']
    if request.form['course']:
        item.course = request.form['course']
    return item
def newMenuItem(restaurant_id):
  if request.method == 'POST':
    item = MenuItem(name=request.form['name'], restaurant_id=restaurant_id)
    item.description = request.form['description']
    item.price = request.form['price']
    session.add(item)
    session.commit()
    flash("New menu item " + item.name + " created!")
    return redirect(url_for('restaurant_menu', restaurant_id=restaurant_id))
  else:
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    return render_template('newmenuitem.html', restaurant=restaurant)
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        newItem = MenuItem(name = request.form['name'], restaurant_id = restaurant_id)
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("Menu Item Created!")
        return redirect(url_for('showMenu', restaurant_id = restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id = restaurant_id)
예제 #9
0
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           restaurant_id=restaurant_id)
        newItem.price = request.form['price']
        newItem.description = request.form['description']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("new menu item created!")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        r = MenuItem()
        r.name = request.form['name']
        r.description = request.form['description']
        r.price = request.form['price']
        r.restaurant_id = restaurant_id
        session.add(r)
        session.commit()
        flash('new item %s created!' % r)
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def menu_item_new(restaurant_id):
    if request.method == "POST":
        with DBSession() as sess:
            menuitem = MenuItem()
            menuitem.restaurant_id = restaurant_id
            menuitem.name = request.form.get('name')
            menuitem.price = request.form.get('price')
            menuitem.description = request.form.get('description')
            menuitem.course = request.form.get('course')
            sess.add(menuitem)
        flash("The new menu item has been created")
        return redirect(url_for('restaurant', restaurant_id=restaurant_id))
    else:
        return render_template("newmenuitem.html", restaurant_id=restaurant_id)
예제 #12
0
def newMenuItem(restaurant_id):
	if 'username' not in login_session:
		return redirect('/login')
	if request.method == 'POST':
		newItem = MenuItem(name = request.form['name'],restaurant_id = restaurant_id, )
		newItem.price = request.form['price']
		newItem.description = request.form['Description']
		newItem.course = request.form['course']
		session.add(newItem)
		session.commit()
		flash("new menu item created")
		return redirect(url_for('restaurants_menu_list',restaurant_id = restaurant_id))
	else:
		return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def newMenuItem(restaurant_id):
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    if request.method == 'POST':
        new_menu_item = MenuItem(name=request.form['name'],
                                 restaurant_id=restaurant_id)
        new_menu_item.description = request.form['description']
        new_menu_item.price = request.form['price']
        new_menu_item.course = request.form['course']
        session.add(new_menu_item)
        session.commit()
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #14
0
def NewMenuItem(restaurant_id):
## This function removes a menu item. A GET request gives a blank form
  session = connectDb()
  if request.method == 'POST':
    restaurant = session.query(Restaurant).filter_by(id = restaurant_id).one()
    newItem = MenuItem(name=request.form['name'],restaurant_id = restaurant_id)
    newItem.description = request.form['description']
    newItem.price       = request.form['price']
    newItem.course      = request.form['course']
    session.add(newItem)
    session.commit()
    flash("%s created to %s." % ( newItem.name, restaurant.name ))
    return redirect(url_for('Menu', restaurant_id = restaurant_id))
  else:
    return render_template('menuitem-new.html', restaurant_id=restaurant_id )
예제 #15
0
def createRestaurantMenu(restaurant_id):  
    if request.method == 'POST':        
        if request.form.get('name',None):         
            newItem = MenuItem(name=request.form['name'], restaurant_id=restaurant_id) 
            if request.form.get('description', None):
                newItem.description = request.form['description']        
            if request.form.get('price', None):
                newItem.price = request.form['price']  
            if request.form.get('course', None):
                newItem.course = request.form['course'] 
            session.add(newItem)
            session.commit()
            flash("A New Menu created!")         
            return redirect(url_for('showRestaurantMenu', restaurant_id = restaurant_id ))                    
    return render_template('newmenuitem.html', restaurant_id = restaurant_id) 
def newMenuItem(restaurant_id):
	restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
	if request.method == "POST":
		if request.form['name']:
			newItem = MenuItem(name = request.form['name'], restaurant_id= restaurant_id)
			newItem.price = '$' + request.form['price']
			newItem.description = request.form['description']
			session.add(newItem)
			session.commit()
			flash("New Menu Item Created!") #a session based message
			return redirect(url_for('menuHome',restaurant_id=restaurant_id))
		else:
			flash("Please enter an item name")
			return redirect(url_for('newMenuItem',restaurant_id=restaurant_id, buttons=config.item_type))
	else:
		return render_template('newMenuItem.html', restaurant=restaurant, buttons=config.item_type)
예제 #17
0
def AddMenuItemToRestaurant(restaurant_id):
    restaurant = getRestaurant(restaurant_id)
    if request.method == 'GET':
        return render_template('newmenuitem.html', restaurant=restaurant)
    else:
        newItem = MenuItem(name=request.form['newMenuItemName'])
        newItem.price = request.form['newMenuItemPrice']
        newItem.description = request.form['newMenuItemDescription']
        newItem.course = request.form['newMenuItemCourse']
        newItem.restaurant_id = restaurant.id
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created: %s for Restaurant: %s" %
              (newItem.name, restaurant.name))
        return redirect(
            url_for('ListRestaurantMenu', restaurant_id=restaurant.id))
예제 #18
0
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedRestaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if editedRestaurant.user_id != login_session['user_id']:
        return "<script> function myfunction() {alert('You are not authorized to edit this restaurant. Please create your own restaurant in order to edit.');}</script><body onload='myfunction()''>"
    if request.method == 'POST':
        newItem = MenuItem(name = request.form['name'], restaurant_id = restaurant_id, user_id = login_session['user_id'])
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created!")
        return redirect(url_for('restaurantMenu', restaurant_id = restaurant_id))
    else:
        return render_template('form.html', restaurant_id = restaurant_id)
예제 #19
0
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        item = MenuItem()
        item.name = request.form['name']
        item.course = request.form['course']
        item.description = request.form['description']
        item.price = request.form['price']
        item.calories = request.form['calories']
        item.image_url = request.form['image_url']
        item.restaurant_id = restaurant_id
        sqlsession.add(item)
        sqlsession.commit()
        flash("Menu Item Created")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        restaurant = sqlsession.query(Restaurant).filter_by(
            id=restaurant_id).one()
        return render_template('newMenuItem.html', restaurant=restaurant)
예제 #20
0
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        item = session.query(Restaurant).filter_by(id=restaurant_id).one()
        if item.user_id != login_session['user_id']:
            return "<script>function myFunction() {alert('Unauthorized');}</script><body onload='myFunction()'>"

        newItem = MenuItem(name=request.form['name'],
                           restaurant_id=restaurant_id)
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("new menu item created.")
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        item = session.query(Restaurant).filter_by(id=restaurant_id).one()
        if item.user_id != login_session['user_id']:
            return "<script>function myFunction() {alert('Unauthorized');}</script><body onload='myFunction()'>"
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #21
0
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedRestaurant = session.query(Restaurant).filter_by(
        id=restaurant_id).one()
    if editedRestaurant.user_id != login_session['user_id']:
        return "<script> function myfunction() {alert('You are not authorized to edit this restaurant. Please create your own restaurant in order to edit.');}</script><body onload='myfunction()''>"
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           restaurant_id=restaurant_id,
                           user_id=login_session['user_id'])
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created!")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('form.html', restaurant_id=restaurant_id)
def newMenuItem(restaurant_id):
	restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
	if request.method == 'POST':
		price = re.search(r'\$\d+\.\d\d', request.form['newItemPrice'])
		if (len(request.form['newItemName']) > 0 and len(request.form['newItemPrice']) > 0 and
			price):
			newItem = MenuItem() 
			newItem.name = request.form['newItemName']
			newItem.description = request.form['newItemDescription']
			newItem.price = request.form['newItemPrice']
			newItem.course = request.form['newItemCourse']
			newItem.restaurant_id = restaurant.id
			session.add(newItem)
			session.commit()
			flash('New menu item created!')
			return redirect(url_for('showMenu', restaurant_id=restaurant_id))
		else:
			flash('Make sure you add a valid new menu item name and valid price when creating a new item')
			return redirect(url_for('showMenu', restaurant_id=restaurant_id))
	else:
		return render_template('addmenuitem.html', restaurant=restaurant)
예제 #23
0
def newMenuItem(restaurant_id):
    """ Create a new menu item. """

    restaurant = database_dao.getRestaurant(restaurant_id)

    if login_session['user_id'] != restaurant.user.id:
        createFeedback(403, 'You dont have permission to access this resource')
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))

    if request.method == 'POST':
        newItem = MenuItem()
        if request.form['name']:
            newItem.name = request.form['name']
        if request.form['description']:
            newItem.description = request.form['description']
        if request.form['price']:
            newItem.price = request.form['price']
        if 'course' in request.form and request.form['course']:
            newItem.course = request.form['course']
        newItem.user_id = restaurant.user_id
        newItem.restaurant_id = restaurant_id

        if (request.form['name'] and request.form['description']
                and request.form['price'] and 'course' in request.form
                and request.form['course']):
            database_dao.update(newItem)

            createFeedback(
                200, 'New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', restaurant_id=restaurant_id))
        else:
            createFeedback(400, 'All Information are needed')
            return render_template('newMenuItem.html',
                                   item=newItem,
                                   restaurant_id=restaurant_id)
    else:
        return render_template('newMenuItem.html',
                               item={},
                               restaurant_id=restaurant_id)
예제 #24
0
def AddMenuItem():
    restaurants = session.query(Restaurant).all()
    new_item = MenuItem()
    if request.method == 'GET':
        return render_template('newMenuItem.html', restaurants=restaurants)

    elif request.method == 'POST':
        if request.form['name']:
            new_item.name = request.form['name']
        if request.form['course']:
            new_item.course = request.form['course']
        if request.form['description']:
            new_item.description = request.form['description']
        if request.form['price']:
            new_item.price = request.form['price']
        if request.form['restaurant_id']:
            new_item.restaurant_id = request.form['restaurant_id']

        session.add(new_item)
        session.commit()
        flash('New Item created!')
        return redirect(url_for('index'))
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    newItem = MenuItem(restaurant_id=restaurant_id,
                       user_id=login_session['user_id'])
    if request.method == 'POST':
        if request.form['name']:
            newItem.name = request.form['name']
        if request.form['description']:
            newItem.description = request.form['description']
        if request.form['price']:
            newItem.price = request.form['price']
        session.add(newItem)
        session.commit()
        flash(newItem.name + " has been created")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id,
                               username=login_session['username'],
                               picture=login_session['picture'])
def AddMenuItem():
    restaurants = session.query(Restaurant).all()
    new_item = MenuItem()
    if request.method == 'GET':
        return render_template('newMenuItem.html', restaurants=restaurants)
        
    elif request.method == 'POST':
        if request.form['name']:
            new_item.name = request.form['name']
        if request.form['course']:
            new_item.course = request.form['course']
        if request.form['description']:
            new_item.description = request.form['description']
        if request.form['price']:
            new_item.price = request.form['price']
        if request.form['restaurant_id']:
            new_item.restaurant_id = request.form['restaurant_id']    
        
        session.add(new_item)
        session.commit()
        flash('New Item created!')
        return redirect(url_for('index'))
예제 #27
0
def restaurant_add_menu_items(restaurant_id):
    if verified is True:
        restaurants = session.query(Restaurant).filter(
            Restaurant.id == restaurant_id)
        for restaurant in restaurants:
            if request.method == 'POST':
                menu_item = MenuItem()
                menu_item.restaurant = restaurant
                if request.form.get('item_name', '') != '':
                    menu_item.name = request.form['item_name']
                if request.form.get('item_description', '') != '':
                    menu_item.description = request.form['item_description']
                if request.form.get('item_price', '') != '':
                    menu_item.price = request.form['item_price']
                if request.form.get('item_course', '') != '':
                    menu_item.course = request.form['item_course']
                session.add(menu_item)
                session.commit()
                flash("new item created")
            elif request.method == 'GET':
                return render_template('add_item.html', restaurant=restaurant)
    return redirect("/restaurant/{}/menu".format(restaurant_id))
예제 #28
0
def newMenuItem(restaurant_id):

    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    session.close()

    if request.method == 'POST':
        # Create the variable to hold the data from the POST
        newItem = MenuItem(restaurant_id=restaurant_id)
        if request.form['name']:
            newItem.name = request.form['name']
        if request.form['description']:
            newItem.description = request.form['description']
        if request.form['price']:
            newItem.price = request.form['price']
        if request.form['course']:
            newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("{} has been added".format(newItem.name))
        session.close()
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newMenuItem.html', restaurant=restaurant)
def fill_menu_item(req_form, restaurant_id):
    new_item = MenuItem(name=req_form['name'], restaurant_id=restaurant_id)
    new_item.description = req_form['desc']
    new_item.price = req_form['price']
    return new_item